├── phpunit.xml.dist ├── includes ├── index.php ├── ajax-actions.php ├── script-loader.php ├── dashboard.php └── class-wp-nearby-events.php ├── tests └── phpunit │ ├── bootstrap.php │ └── test-wpNearbyEvents.php ├── nearby-wordpress-events.php ├── css └── dashboard.css ├── readme.txt ├── js └── dashboard.js └── license.txt /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | ./tests/phpunit 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /includes/index.php: -------------------------------------------------------------------------------- 1 | get_events( $search, $timezone ); 21 | 22 | if ( is_wp_error( $events ) ) { 23 | wp_send_json_error( array( 24 | 'error' => $events->get_error_message(), 25 | ) ); 26 | } else { 27 | if ( isset( $events['location'] ) && ( $search || ! $user_location ) ) { 28 | // Store the location network-wide, so the user doesn't have to set it on each site. 29 | update_user_option( $user_id, 'nearbywp-location', $events['location'], true ); 30 | } 31 | 32 | wp_send_json_success( $events ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/phpunit/bootstrap.php: -------------------------------------------------------------------------------- 1 | wp_create_nonce( 'nearbywp_events' ), 43 | 'cachedData' => $nearby_events->get_cached_events(), 44 | 45 | 'l10n' => array( 46 | 'enter_closest_city' => __( 'Enter your closest city name to find nearby events', 'nearby-wp-events' ), 47 | 'error_occurred_please_try_again' => __( 'An error occured. Please try again.', 'nearby-wp-events' ), 48 | 49 | /* 50 | * These specific examples were chosen to highlight the fact that a 51 | * state is not needed, even for cities whose name is not unique. 52 | * It would be too cumbersome to include that in the instructions 53 | * to the user, so it's left as an implication. 54 | */ 55 | /* translators: %s is the name of the city we couldn't locate. Replace the examples with cities in your locale, but test that they match the expected location before including them. Use endonyms (native locale names) whenever possible. */ 56 | 'could_not_locate_city' => __( 'We couldn\'t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.', 'nearby-wp-events' ), 57 | 58 | // This one is only used with wp.a11y.speak(), so it can/should be more brief. 59 | /* translators: %s is the name of a city. */ 60 | 'city_updated' => __( 'City updated. Listing events near %s.', 'nearby-wp-events' ), 61 | ) 62 | ); 63 | 64 | return $inline_script_data; 65 | } 66 | -------------------------------------------------------------------------------- /nearby-wordpress-events.php: -------------------------------------------------------------------------------- 1 | p { 55 | margin-bottom: 0; 56 | display: inline; 57 | } 58 | 59 | #nearbywp-submit { 60 | margin-left: 2px; 61 | } 62 | 63 | .nearbywp-cancel.button.button-link { 64 | color: #0073aa; 65 | text-decoration: underline; 66 | margin-left: 2px; 67 | } 68 | 69 | .nearbywp ul { 70 | background-color: #fafafa; 71 | padding-left: 0; 72 | padding-right: 0; 73 | padding-bottom: 0; 74 | } 75 | 76 | .nearbywp li { 77 | margin: 0; 78 | padding: 8px 12px; 79 | color: #72777c; 80 | } 81 | .nearbywp li:first-child { 82 | border-top: 1px solid #eee; 83 | } 84 | 85 | .nearbywp li ~ li { 86 | border-top: 1px solid #eee; 87 | } 88 | 89 | .nearbywp .activity-block { 90 | border-bottom: 0; 91 | } 92 | .nearbywp .activity-block.last { 93 | border-bottom: 1px solid #eee; 94 | padding-top: 0; 95 | } 96 | 97 | .nearbywp .event-info { 98 | display: block; 99 | } 100 | @media screen and (min-width: 355px) { 101 | .nearbywp .event-info { 102 | display: table-row; 103 | float: left; 104 | max-width: 59%; 105 | } 106 | .rtl .nearbywp .event-info { 107 | float: right; 108 | } 109 | } 110 | 111 | .event-icon { 112 | height: 18px; 113 | padding-right: 10px; 114 | width: 18px; 115 | display: none; /* Hide on smaller screens */ 116 | } 117 | .rtl .event-icon { 118 | padding-right: 0; 119 | padding-left: 10px; 120 | } 121 | @media screen and (min-width: 355px) { 122 | .event-icon { 123 | display: table-cell; 124 | } 125 | } 126 | 127 | .event-icon:before { 128 | color: #82878C; 129 | font-size: 18px; 130 | } 131 | .event-meetup .event-icon:before { 132 | content: "\f484"; 133 | } 134 | .event-wordcamp .event-icon:before { 135 | content: "\f486"; 136 | } 137 | 138 | @media screen and (min-width: 355px) { 139 | .event-info-inner { 140 | display: table-cell; 141 | } 142 | } 143 | 144 | .nearbywp .event-title { 145 | font-weight: 600; 146 | display: block; 147 | } 148 | 149 | @media screen and (min-width: 355px) { 150 | .nearbywp .event-date-time { 151 | float: right; 152 | max-width: 39%; 153 | } 154 | .rtl .nearbywp .event-date-time { 155 | float: left; 156 | } 157 | } 158 | 159 | .nearbywp .event-date, 160 | .nearbywp .event-time { 161 | display: block; 162 | } 163 | @media screen and (min-width: 355px) { 164 | .nearbywp .event-date, 165 | .nearbywp .event-time { 166 | text-align: right; 167 | } 168 | .rtl .nearbywp .event-date, 169 | .rtl .nearbywp .event-time { 170 | text-align: left; 171 | } 172 | } 173 | 174 | .nearbywp-footer { 175 | margin-top: 0; 176 | margin-bottom: 0; 177 | margin-left: -12px; 178 | width: 100%; 179 | padding: 12px 12px 0; 180 | border-top: 1px solid #eee; 181 | color: #ddd; 182 | } 183 | .rtl .nearbywp-footer { 184 | margin-right: -12px; 185 | } 186 | 187 | 188 | /* News styles */ 189 | 190 | .dashboard-news-plugin, 191 | .rssSummary, 192 | .rss-date { 193 | display: none; 194 | } 195 | 196 | #dashboard_primary .rss-widget { 197 | padding: 0; 198 | border-bottom: none; 199 | } 200 | 201 | #dashboard_primary .rss-widget > ul > li { 202 | padding: 6px 0; 203 | margin: 0; 204 | } 205 | 206 | #dashboard_primary .rss-widget > ul > li:nth-child(3n) { 207 | padding-bottom: 12px; 208 | } 209 | 210 | #dashboard_primary .rss-widget a.rsswidget { 211 | font-size: 13px; 212 | line-height: 1.4; 213 | } 214 | 215 | #dashboard_primary .rss-widget:last-child { 216 | padding: 0; 217 | } 218 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Nearby WordPress Events === 2 | Contributors: afercia, andreamiddleton, azaozz, camikaos, coreymckrill, chanthaboune, courtneypk, dd32, iandunn, iseulde, mapk, mayukojpn, melchoyce, nao, obenland, pento, samuelsidler, stephdau, tellyworth 3 | Donate link: https://eff.org 4 | Tags: meetup, wordcamp, events, dashboard widget 5 | Requires at least: 4.7 6 | Tested up to: 4.7.4 7 | Stable tag: 0.8 8 | License: GPL2 9 | License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Shows you upcoming local WordPress events in your wp-admin Dashboard 12 | 13 | 14 | == Description == 15 | 16 | The plugin updates the existing WordPress News dashboard widget to also include upcoming meetup events and WordCamps near the current user's location. If you have multiple users on your site, each one will be shown the events that are close to their individual location. The dashboard widget will try to automatically detect their location, but they'll also be able to enter any city they like. 17 | 18 | 19 | ### Why? 20 | 21 | The community that has been created around WordPress is one of its best features, and one of the primary reasons for its success, but many users are still unaware that it exists, and aren't taking advantage of all of the resources that it makes available to them. 22 | 23 | Inviting more people to join the community will help to increase its overall health, diversity, and effectiveness, which in turn helps to ensure that WordPress will continue to thrive in the years to come. 24 | 25 | wp-admin is the perfect place to display these events, because that’s the place where almost all WordPress users are visiting already. Instead of expecting them to come to us, we can bring the relevant information directly to them. 26 | 27 | 28 | == Frequently Asked Questions == 29 | 30 | = What information is collected, and what is it used for? = 31 | 32 | The plugin sends each user's timezone, locale, and IP address to `api.wordpress.org`, in order to determine their location, so that they can be shown events that are close to that location. If the user requests events near a specific city, then that is also sent. The data is not stored permanently, not used for any other purpose, and not shared with anyone outside of WordPress.org, with the exception of any conditions covered in the [WordPress.org privacy policy](https://wordpress.org/about/privacy/). 33 | 34 | 35 | 36 | == Screenshots == 37 | 38 | 1. The new combined Events and News widget when a location and events are available 39 | 2. The widget when no location is available 40 | 3. The widget when a location is available, but there are no upcoming events nearby 41 | 42 | 43 | == Installation == 44 | 45 | For help installing this (or any other) WordPress plugin, please read the [Managing Plugins](http://codex.wordpress.org/Managing_Plugins) article on the Codex. 46 | 47 | 48 | == Changelog == 49 | = 0.8 (2017-05-10) = 50 | * [FIX] Update criteria plugin uses to detect if the functionality has been merged into Core. 51 | * [FIX] Bring back the Cancel button on the city search form. 52 | * [FIX] Minor UI tweaks and semantic code changes. 53 | 54 | = 0.7 (2017-05-03) = 55 | * [NEW] Dynamic content changes are announced to screenreaders. 56 | * [NEW] Log API responses to aid with troubleshooting. 57 | * [FIX] Minimize re-rendering of dynamic content to aid screenreaders. 58 | 59 | = 0.6 (2017-04-24) = 60 | * [FIX] Fixed fatal conflict with asynchronous uploads by restricting the bootstrap process to only the contexts where it's necessary. 61 | * [FIX] Restore the behavior that automatically focuses the input on the city field when toggling the location form. 62 | 63 | = 0.5 (2017-04-21) = 64 | * [SECURITY] Harden the city display name against a theoretical cross-site scripting attack. 65 | * [FIX] Add a label to the city input field, instead of relying on the placeholder. 66 | * [FIX] Handled AJAX error more gracefully 67 | * [FIX] Events older than 24 hours are no longer shown 68 | * [NEW] The location icon can now be clicked on to close the location form 69 | * [NEW] The plugin will disable itself if it detects that the functionality has been merged into Core 70 | 71 | = 0.4 (2017-04-11) = 72 | * [FIX] Improved the layout on mobile devices. 73 | * [FIX] Added styles for right-to-left languages. 74 | * [NEW] Added the event's time and day of the week, so that users don't have to open the event link to see if it fits their schedule. 75 | 76 | = 0.3 (2017-03-31) = 77 | * [SECURITY] Harden the error message handling against a theoretical cross-site scripting attack. 78 | * [FIX] Locations are now saved network-wide in Multisite installs, so you no longer have to set your location on each site. Unfortunately, you may need to re-save your location the first time you visit wp-admin because of this. 79 | * [FIX] Events are now cached network-wide in Multisite installs, to improve performance. 80 | * [FIX] Events are now shown on the Network Dashboard in Multisite installs. 81 | 82 | = 0.2 (2017-03-24) = 83 | * [FIX] Fix a bug that prevented events from being cached. The widget loads much faster now. 84 | * [FIX] Fix a bug that prevented debugging info from being added to AJAX responses. 85 | 86 | = 0.1 (2017-03-20) = 87 | * First version 88 | 89 | 90 | == Upgrade Notice == 91 | 92 | = 0.8 = 93 | This version updates the check that disables the plugin if its functionality has been merged into Core. 94 | 95 | = 0.7 = 96 | This version makes several improvements for screenreaders and fixes minor bugs. 97 | 98 | = 0.6 = 99 | This version fixes a critical bug in 0.5 that caused file uploads to break in certain situations. 100 | 101 | = 0.5 = 102 | This version fixes several bugs and accessibility issues, and protects against a theoretical security vulnerability. 103 | 104 | = 0.4 = 105 | This version displays the event time and day of the week, and fixes a few small bugs. 106 | 107 | = 0.3 = 108 | This version fixes a few bugs in Multisite installs, and protects against a theoretical security vulnerability. 109 | 110 | = 0.2 = 111 | This version has a few minor bugs fixes and user-experience improvements. 112 | -------------------------------------------------------------------------------- /includes/dashboard.php: -------------------------------------------------------------------------------- 1 | 28 | 29 |
30 |

31 | 32 |

33 | 34 | 37 | 38 | 39 |
40 | 41 | 42 | 43 | 44 | 45 | 54 | 83 | 84 |
85 |
86 | 87 |
88 |
89 | 90 | 108 | 109 | 121 | 122 | 132 | 133 | 142 | 143 | 163 | 164 | 176 | 177 | instance = new WP_Nearby_Events( 1, $this->get_user_location() ); 36 | } 37 | 38 | /** 39 | * Simulate a stored user location. 40 | * 41 | * @access private 42 | * @since 4.8.0 43 | * 44 | * @return array The mock location. 45 | */ 46 | private function get_user_location() { 47 | return array( 48 | 'description' => 'San Francisco', 49 | 'latitude' => '37.7749300', 50 | 'longitude' => '-122.4194200', 51 | 'country' => 'US', 52 | ); 53 | } 54 | 55 | /** 56 | * Test: `get_events()` should return an instance of WP_Error if the response code is not 200. 57 | * 58 | * @access public 59 | * @since 4.8.0 60 | */ 61 | public function test_get_events_bad_response_code() { 62 | add_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) ); 63 | 64 | $this->assertWPError( $this->instance->get_events() ); 65 | 66 | remove_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) ); 67 | } 68 | 69 | /** 70 | * Test: The response body should not be cached if the response code is not 200. 71 | * 72 | * @access public 73 | * @since 4.8.0 74 | */ 75 | public function test_get_cached_events_bad_response_code() { 76 | add_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) ); 77 | 78 | $this->instance->get_events(); 79 | 80 | $this->assertFalse( $this->instance->get_cached_events() ); 81 | 82 | remove_filter( 'pre_http_request', array( $this, '_http_request_bad_response_code' ) ); 83 | } 84 | 85 | /** 86 | * Simulate an HTTP response with a non-200 response code. 87 | * 88 | * @access public 89 | * @since 4.8.0 90 | * 91 | * @return array A mock response with a 404 HTTP status code 92 | */ 93 | public function _http_request_bad_response_code() { 94 | return array( 95 | 'headers' => '', 96 | 'body' => '', 97 | 'response' => array( 98 | 'code' => 404, 99 | ), 100 | 'cookies' => '', 101 | 'filename' => '', 102 | ); 103 | } 104 | 105 | /** 106 | * Test: `get_events()` should return an instance of WP_Error if the response body does not have 107 | * the required properties. 108 | * 109 | * @access public 110 | * @since 4.8.0 111 | */ 112 | public function test_get_events_invalid_response() { 113 | add_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) ); 114 | 115 | $this->assertWPError( $this->instance->get_events() ); 116 | 117 | remove_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) ); 118 | } 119 | 120 | /** 121 | * Test: The response body should not be cached if it does not have the required properties. 122 | * 123 | * @access public 124 | * @since 4.8.0 125 | */ 126 | public function test_get_cached_events_invalid_response() { 127 | add_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) ); 128 | 129 | $this->instance->get_events(); 130 | 131 | $this->assertFalse( $this->instance->get_cached_events() ); 132 | 133 | remove_filter( 'pre_http_request', array( $this, '_http_request_invalid_response' ) ); 134 | } 135 | 136 | /** 137 | * Simulate an HTTP response with a body that does not have the required properties. 138 | * 139 | * @access public 140 | * @since 4.8.0 141 | * 142 | * @return array A mock response that's missing required properties. 143 | */ 144 | public function _http_request_invalid_response() { 145 | return array( 146 | 'headers' => '', 147 | 'body' => wp_json_encode( array() ), 148 | 'response' => array( 149 | 'code' => 200, 150 | ), 151 | 'cookies' => '', 152 | 'filename' => '', 153 | ); 154 | } 155 | 156 | /** 157 | * Test: With a valid response, `get_events()` should return an associated array containing a location array and 158 | * an events array with individual events that have formatted time and date. 159 | * 160 | * @access public 161 | * @since 4.8.0 162 | */ 163 | public function test_get_events_valid_response() { 164 | add_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) ); 165 | 166 | $response = $this->instance->get_events(); 167 | 168 | $this->assertNotWPError( $response ); 169 | $this->assertEqualSetsWithIndex( $this->get_user_location(), $response['location'] ); 170 | $this->assertEquals( date( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $response['events'][0]['formatted_date'] ); 171 | $this->assertEquals( '1:00 pm', $response['events'][0]['formatted_time'] ); 172 | 173 | remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) ); 174 | } 175 | 176 | /** 177 | * Test: `get_cached_events()` should return the same data as `get_events()`, including formatted time 178 | * and date values for each event. 179 | * 180 | * @access public 181 | * @since 4.8.0 182 | */ 183 | public function test_get_cached_events_valid_response() { 184 | add_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) ); 185 | 186 | $this->instance->get_events(); 187 | 188 | $cached_events = $this->instance->get_cached_events(); 189 | 190 | $this->assertNotWPError( $cached_events ); 191 | $this->assertEqualSetsWithIndex( $this->get_user_location(), $cached_events['location'] ); 192 | $this->assertEquals( date( 'l, M j, Y', strtotime( 'next Sunday 1pm' ) ), $cached_events['events'][0]['formatted_date'] ); 193 | $this->assertEquals( '1:00 pm', $cached_events['events'][0]['formatted_time'] ); 194 | 195 | remove_filter( 'pre_http_request', array( $this, '_http_request_valid_response' ) ); 196 | } 197 | 198 | /** 199 | * Simulate an HTTP response with valid location and event data. 200 | * 201 | * @access public 202 | * @since 4.8.0 203 | * 204 | * @return array A mock HTTP response with valid data. 205 | */ 206 | public function _http_request_valid_response() { 207 | return array( 208 | 'headers' => '', 209 | 'body' => wp_json_encode( array( 210 | 'location' => $this->get_user_location(), 211 | 'events' => array( 212 | array( 213 | 'type' => 'meetup', 214 | 'title' => 'Flexbox + CSS Grid: Magic for Responsive Layouts', 215 | 'url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/events/236031233/', 216 | 'meetup' => 'The East Bay WordPress Meetup Group', 217 | 'meetup_url' => 'https://www.meetup.com/Eastbay-WordPress-Meetup/', 218 | 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Sunday 1pm' ) ), 219 | 'location' => array( 220 | 'location' => 'Oakland, CA, USA', 221 | 'country' => 'us', 222 | 'latitude' => 37.808453, 223 | 'longitude' => -122.26593, 224 | ), 225 | ), 226 | array( 227 | 'type' => 'meetup', 228 | 'title' => 'Part 3- Site Maintenance - Tools to Make It Easy', 229 | 'url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/events/237706839/', 230 | 'meetup' => 'WordPress Bay Area Foothills Group', 231 | 'meetup_url' => 'https://www.meetup.com/Wordpress-Bay-Area-CA-Foothills/', 232 | 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Wednesday 1:30pm' ) ), 233 | 'location' => array( 234 | 'location' => 'Milpitas, CA, USA', 235 | 'country' => 'us', 236 | 'latitude' => 37.432813, 237 | 'longitude' => -121.907095, 238 | ), 239 | ), 240 | array( 241 | 'type' => 'wordcamp', 242 | 'title' => 'WordCamp Kansas City', 243 | 'url' => 'https://2017.kansascity.wordcamp.org', 244 | 'meetup' => null, 245 | 'meetup_url' => null, 246 | 'date' => date( 'Y-m-d H:i:s', strtotime( 'next Saturday' ) ), 247 | 'location' => array( 248 | 'location' => 'Kansas City, MO', 249 | 'country' => 'US', 250 | 'latitude' => 39.0392325, 251 | 'longitude' => -94.577076, 252 | ), 253 | ), 254 | ), 255 | ) ), 256 | 'response' => array( 257 | 'code' => 200, 258 | ), 259 | 'cookies' => '', 260 | 'filename' => '', 261 | ); 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /js/dashboard.js: -------------------------------------------------------------------------------- 1 | wp.NearbyWP = wp.NearbyWP || {}; 2 | 3 | jQuery( function( $ ) { 4 | 'use strict'; 5 | 6 | var app = wp.NearbyWP.Dashboard = { 7 | initialized: false, 8 | 9 | /** 10 | * Main entry point 11 | * 12 | * @since 4.8.0 13 | */ 14 | init: function() { 15 | if ( app.initialized ) { 16 | return; 17 | } 18 | 19 | var $container = $( '#nearbywp' ); 20 | 21 | /* 22 | * When JavaScript is disabled, the errors container is shown, so 23 | * that "This widget requires Javascript" message can be seen. 24 | * 25 | * When JS is enabled, the container is hidden at first, and then 26 | * revealed during the template rendering, if there actually are 27 | * errors to show. 28 | * 29 | * The display indicator switches from `hide-if-js` to `aria-hidden` 30 | * here in order to maintain consistency with all the other fields 31 | * that key off of `aria-hidden` to determine their visibility. 32 | * `aria-hidden` can't be used initially, because there would be no 33 | * way to set it to false when JavaScript is disabled, which would 34 | * prevent people from seeing the "This widget requires JavaScript" 35 | * message. 36 | */ 37 | $( '.nearbywp-errors' ) 38 | .attr( 'aria-hidden', true ) 39 | .removeClass( 'hide-if-js' ); 40 | 41 | $container.on( 'click', '#nearbywp-toggle-location', app.toggleLocationForm ); 42 | $container.on( 'click', '.nearbywp-cancel', app.toggleLocationForm ); 43 | 44 | $container.on( 'submit', '#nearbywp-form', function( event ) { 45 | event.preventDefault(); 46 | 47 | app.getEvents( { 48 | location: $( '#nearbywp-location' ).val() 49 | } ) 50 | }); 51 | 52 | if ( nearbyWPData.cachedData.location && nearbyWPData.cachedData.events ) { 53 | app.renderEventsTemplate( nearbyWPData.cachedData, 'app' ); 54 | } else { 55 | app.getEvents(); 56 | } 57 | 58 | app.initialized = true; 59 | }, 60 | 61 | /** 62 | * Toggle the visibility of the Edit Location form 63 | * 64 | * @since 4.8.0 65 | * 66 | * @param {event|string} action 'show' or 'hide' to specify a state; 67 | * Or an event object to flip between states 68 | */ 69 | toggleLocationForm : function( action ) { 70 | var $toggleButton = $( '#nearbywp-toggle-location' ), 71 | $cancelButton = $( '.nearbywp-cancel' ), 72 | $form = $( '#nearbywp-form' ); 73 | 74 | if ( 'object' === typeof action ) { 75 | // Strict comparison doesn't work in this case. 76 | action = 'true' == $toggleButton.attr( 'aria-expanded' ) ? 'hide' : 'show'; 77 | } 78 | 79 | if ( 'hide' === action ) { 80 | $toggleButton.attr( 'aria-expanded', false ); 81 | $cancelButton.attr( 'aria-expanded', false ); 82 | $form.attr( 'aria-hidden', true ); 83 | } else { 84 | $toggleButton.attr( 'aria-expanded', true ); 85 | $cancelButton.attr( 'aria-expanded', true ); 86 | $form.attr( 'aria-hidden', false ); 87 | } 88 | }, 89 | 90 | /** 91 | * Send Ajax request to fetch events for the widget 92 | * 93 | * @since 4.8.0 94 | * 95 | * @param {object} requestParams 96 | */ 97 | getEvents: function( requestParams ) { 98 | var initiatedBy, 99 | $spinner = $( '#nearbywp-form' ).children( '.spinner' ); 100 | 101 | requestParams = requestParams || {}; 102 | requestParams._wpnonce = nearbyWPData.nonce; 103 | requestParams.timezone = window.Intl ? window.Intl.DateTimeFormat().resolvedOptions().timeZone : ''; 104 | 105 | initiatedBy = requestParams.location ? 'user' : 'app'; 106 | 107 | $spinner.addClass( 'is-active' ); 108 | 109 | wp.ajax.post( 'nearbywp_get_events', requestParams ) 110 | .always( function() { 111 | $spinner.removeClass( 'is-active' ); 112 | }) 113 | .done( function( successfulResponse ) { 114 | if ( 'no_location_available' === successfulResponse.error ) { 115 | if ( requestParams.location ) { 116 | successfulResponse.unknownCity = requestParams.location; 117 | } else { 118 | /* 119 | * No location was passed, which means that this was an automatic query 120 | * based on IP, locale, and timezone. Since the user didn't initiate it, 121 | * it should fail silently. Otherwise, the error could confuse and/or 122 | * annoy them. 123 | */ 124 | delete successfulResponse.error; 125 | } 126 | } 127 | 128 | app.renderEventsTemplate( successfulResponse, initiatedBy ); 129 | }) 130 | .fail( function( failedResponse ) { 131 | app.renderEventsTemplate( { 132 | 'location' : false, 133 | 'error' : true 134 | }, initiatedBy ); 135 | }); 136 | }, 137 | 138 | /** 139 | * Render the template for the Events section of the Events & News widget 140 | * 141 | * @since 4.8.0 142 | * 143 | * @param {Object} templateParams The various parameters that will get passed to wp.template 144 | * @param {string} initiatedBy 'user' to indicate that this was triggered manually by the user; 145 | * 'app' to indicate it was triggered automatically by the app itself. 146 | */ 147 | renderEventsTemplate : function( templateParams, initiatedBy ) { 148 | var template, 149 | elementVisibility, 150 | $locationMessage = $( '#nearbywp-location-message' ), 151 | $results = $( '#nearbywp-results' ); 152 | 153 | /* 154 | * Hide all toggleable elements by default, to keep the logic simple. 155 | * Otherwise, each block below would have to turn hide everything that 156 | * could have been shown at an earlier point. 157 | * 158 | * The exception to that is that the .nearbywp container. It's hidden 159 | * when the page is first loaded, because the content isn't ready yet, 160 | * but once we've reached this point, it should always be shown. 161 | */ 162 | elementVisibility = { 163 | '.nearbywp' : true, 164 | '.nearbywp-loading' : false, 165 | '.nearbywp-errors' : false, 166 | '.nearbywp-error-occurred' : false, 167 | '.nearbywp-could-not-locate' : false, 168 | '#nearbywp-location-message' : false, 169 | '#nearbywp-toggle-location' : false, 170 | '#nearbywp-results' : false 171 | }; 172 | 173 | /* 174 | * Determine which templates should be rendered and which elements 175 | * should be displayed 176 | */ 177 | if ( templateParams.location.description ) { 178 | template = wp.template( 'nearbywp-attend-event-near' ); 179 | $locationMessage.html( template( templateParams ) ); 180 | 181 | if ( templateParams.events.length ) { 182 | template = wp.template( 'nearbywp-event-list' ); 183 | $results.html( template( templateParams ) ); 184 | } else { 185 | template = wp.template( 'nearbywp-no-upcoming-events' ); 186 | $results.html( template( templateParams ) ); 187 | } 188 | wp.a11y.speak( nearbyWPData.l10n.city_updated.replace( /%s/g, templateParams.location.description ) ); 189 | 190 | elementVisibility['#nearbywp-location-message'] = true; 191 | elementVisibility['#nearbywp-toggle-location'] = true; 192 | elementVisibility['#nearbywp-results'] = true; 193 | 194 | } else if ( templateParams.unknownCity ) { 195 | template = wp.template( 'nearbywp-could-not-locate' ); 196 | $( '.nearbywp-could-not-locate' ).html( template( templateParams ) ); 197 | wp.a11y.speak( nearbyWPData.l10n.could_not_locate_city.replace( /%s/g, templateParams.unknownCity ) ); 198 | 199 | elementVisibility['.nearbywp-errors'] = true; 200 | elementVisibility['.nearbywp-could-not-locate'] = true; 201 | 202 | } else if ( templateParams.error && 'user' === initiatedBy ) { 203 | /* 204 | * Errors messages are only shown for requests that were initiated 205 | * by the user, not for ones that were initiated by the app itself. 206 | * Showing error messages for an event that user isn't aware of 207 | * could be confusing or unnecessarily distracting. 208 | */ 209 | wp.a11y.speak( nearbyWPData.l10n.error_occurred_please_try_again ); 210 | 211 | elementVisibility['.nearbywp-errors'] = true; 212 | elementVisibility['.nearbywp-error-occurred'] = true; 213 | 214 | } else { 215 | $locationMessage.text( nearbyWPData.l10n.enter_closest_city ); 216 | 217 | elementVisibility['#nearbywp-location-message'] = true; 218 | elementVisibility['#nearbywp-toggle-location'] = true; 219 | } 220 | 221 | // Set the visibility of toggleable elements. 222 | _.each( elementVisibility, function( isVisible, element ) { 223 | $( element ).attr( 'aria-hidden', ! isVisible ); 224 | } ); 225 | 226 | $( '#nearbywp-toggle-location' ).attr( 'aria-expanded', elementVisibility['#nearbywp-toggle-location'] ); 227 | 228 | /* 229 | * During the initial page load, the location form should be hidden 230 | * by default if the user has saved a valid location during a previous 231 | * session. It's safe to assume that they want to continue using that 232 | * location, and displaying the form would unnecessarily clutter the 233 | * widget. 234 | */ 235 | if ( 'app' === initiatedBy && templateParams.location.description ) { 236 | app.toggleLocationForm( 'hide' ); 237 | } else { 238 | app.toggleLocationForm( 'show' ); 239 | } 240 | } 241 | }; 242 | 243 | if ( $( '#nearbywp_dashboard_events' ).is( ':visible' ) ) { 244 | app.init(); 245 | } else { 246 | $( document ).on( 'postbox-toggled', function( event, postbox ) { 247 | var $postbox = $( postbox ); 248 | 249 | if ( 'nearbywp_dashboard_events' === $postbox.attr( 'id' ) && $postbox.is( ':visible' ) ) { 250 | app.init(); 251 | } 252 | }); 253 | } 254 | }); 255 | -------------------------------------------------------------------------------- /includes/class-wp-nearby-events.php: -------------------------------------------------------------------------------- 1 | user_id = absint( $user_id ); 60 | $this->user_location = $user_location; 61 | } 62 | 63 | /** 64 | * Get data about events near a particular location. 65 | * 66 | * If the `user_location` property is set and there are cached events for this 67 | * location, these will be immediately returned. 68 | * 69 | * If not, this method will send a request to the Events API with location data. 70 | * The API will send back a recognized location based on the data, along with 71 | * nearby events. 72 | * 73 | * @access public 74 | * @since 4.8.0 75 | * 76 | * @param string $location_search Optional search string to help determine the location. 77 | * Default empty string. 78 | * @param string $timezone Optional timezone to help determine the location. 79 | * Default empty string. 80 | * @return array|WP_Error A WP_Error on failure; an array with location and events on 81 | * success. 82 | */ 83 | public function get_events( $location_search = '', $timezone = '' ) { 84 | $cached_events = $this->get_cached_events(); 85 | 86 | if ( ! $location_search && $cached_events ) { 87 | return $cached_events; 88 | } 89 | 90 | $request_url = $this->get_request_url( $location_search, $timezone ); 91 | $response = wp_remote_get( $request_url ); 92 | $response_code = wp_remote_retrieve_response_code( $response ); 93 | $response_body = json_decode( wp_remote_retrieve_body( $response ), true ); 94 | 95 | $response_error = null; 96 | $debugging_info = compact( 'request_url', 'response_code', 'response_body' ); 97 | 98 | if ( is_wp_error( $response ) ) { 99 | $response_error = $response; 100 | } elseif ( 200 !== $response_code ) { 101 | $response_error = new WP_Error( 102 | 'api-error', 103 | /* translators: %s is a numeric HTTP status code; e.g., 400, 403, 500, 504, etc. */ 104 | esc_html( sprintf( __( 'Invalid API response code (%d)', 'nearby-wp-events' ), $response_code ) ) 105 | ); 106 | } elseif ( ! isset( $response_body['location'], $response_body['events'] ) ) { 107 | $response_error = new WP_Error( 108 | 'api-invalid-response', 109 | isset( $response_body['error'] ) ? $response_body['error'] : __( 'Unknown API error.', 'nearby-wp-events' ) 110 | ); 111 | } 112 | 113 | if ( is_wp_error( $response_error ) ) { 114 | $this->maybe_log_events_response( $response->get_error_message(), $debugging_info ); 115 | 116 | return $response_error; 117 | } else { 118 | $this->cache_events( $response_body ); 119 | 120 | $response_body = $this->trim_events( $response_body ); 121 | $response_body = $this->format_event_data_time( $response_body ); 122 | 123 | // Avoid bloating the log with all the event data, but keep the count. 124 | $debugging_info['response_body']['events'] = count( $debugging_info['response_body']['events'] ) . ' events trimmed.'; 125 | 126 | $this->maybe_log_events_response( 'Valid response received', $debugging_info ); 127 | 128 | return $response_body; 129 | } 130 | } 131 | 132 | /** 133 | * Build a URL for requests to the Events API 134 | * 135 | * @access protected 136 | * @since 4.8.0 137 | * 138 | * @param string $search City search string. Default empty string. 139 | * @param string $timezone Timezone string. Default empty string. 140 | * @return string The request URL. 141 | */ 142 | protected function get_request_url( $search = '', $timezone = '' ) { 143 | $api_url = 'https://api.wordpress.org/events/1.0/'; 144 | 145 | $args = array( 146 | 'number' => 5, // Get more than three in case some get trimmed out. 147 | 'ip' => $this->get_unsafe_client_ip(), 148 | 'locale' => get_user_locale( $this->user_id ), 149 | ); 150 | 151 | if ( $timezone ) { 152 | $args['timezone'] = $timezone; 153 | } 154 | 155 | if ( $search ) { 156 | $args['location'] = $search; 157 | } elseif ( isset( $this->user_location['latitude'], $this->user_location['longitude'] ) ) { 158 | // Send pre-determined location. 159 | $args['latitude'] = $this->user_location['latitude']; 160 | $args['longitude'] = $this->user_location['longitude']; 161 | } 162 | 163 | return add_query_arg( $args, $api_url ); 164 | } 165 | 166 | /** 167 | * Determine the user's actual IP if possible 168 | * 169 | * If the user is making their request through a proxy, or if the web server 170 | * is behind a proxy, then $_SERVER['REMOTE_ADDR'] will be the proxy address 171 | * rather than the user's actual address. 172 | * 173 | * Modified from http://stackoverflow.com/a/2031935/450127. 174 | * 175 | * SECURITY WARNING: This function is _NOT_ intended to be used in 176 | * circumstances where the authenticity of the IP address matters. This does 177 | * _NOT_ guarantee that the returned address is valid or accurate, and it can 178 | * be easily spoofed. 179 | * 180 | * @access protected 181 | * @since 4.8.0 182 | * 183 | * @return false|string `false` on failure, the `string` address on success 184 | */ 185 | protected function get_unsafe_client_ip() { 186 | $client_ip = false; 187 | 188 | // In order of preference, with the best ones for this purpose first. 189 | $address_headers = array( 190 | 'HTTP_CLIENT_IP', 191 | 'HTTP_X_FORWARDED_FOR', 192 | 'HTTP_X_FORWARDED', 193 | 'HTTP_X_CLUSTER_CLIENT_IP', 194 | 'HTTP_FORWARDED_FOR', 195 | 'HTTP_FORWARDED', 196 | 'REMOTE_ADDR', 197 | ); 198 | 199 | foreach ( $address_headers as $header ) { 200 | if ( array_key_exists( $header, $_SERVER ) ) { 201 | /* 202 | * HTTP_X_FORWARDED_FOR can contain a chain of comma-separated 203 | * addresses. The first one is the original client. It can't be 204 | * trusted for authenticity, but we don't need to for this purpose. 205 | */ 206 | $address_chain = explode( ',', $_SERVER[ $header ] ); 207 | $client_ip = trim( $address_chain[0] ); 208 | 209 | break; 210 | } 211 | } 212 | 213 | return $client_ip; 214 | } 215 | 216 | /** 217 | * Generate a transient key based on user location 218 | * 219 | * This could be reduced to a one-liner in the calling functions, but it's 220 | * intentionally a separate function because it's called from multiple 221 | * locations, and having it abstracted keeps the logic consistent and DRY, 222 | * which is less prone to errors. 223 | * 224 | * @access protected 225 | * @since 4.8.0 226 | * 227 | * @param array $location Should contain 'latitude' and 'longitude' indexes. 228 | * @return bool|string `false` on failure, or a string on success 229 | */ 230 | protected function get_events_transient_key( $location ) { 231 | $key = false; 232 | 233 | if ( isset( $location['latitude'], $location['longitude'] ) ) { 234 | $key = 'nearbywp-' . md5( $location['latitude'] . $location['longitude'] ); 235 | } 236 | 237 | return $key; 238 | } 239 | 240 | /** 241 | * Cache an array of events data from the Events API. 242 | * 243 | * @access protected 244 | * @since 4.8.0 245 | * 246 | * @param array $events Response body from the API request. 247 | * @return bool `true` if events were cached; `false` if not. 248 | */ 249 | protected function cache_events( $events ) { 250 | $set = false; 251 | $transient_key = $this->get_events_transient_key( $events['location'] ); 252 | $cache_expiration = isset( $events['ttl'] ) ? absint( $events['ttl'] ) : HOUR_IN_SECONDS * 12; 253 | 254 | if ( $transient_key ) { 255 | $set = set_site_transient( $transient_key, $events, $cache_expiration ); 256 | } 257 | 258 | return $set; 259 | } 260 | 261 | /** 262 | * Get cached events 263 | * 264 | * @access public 265 | * @since 4.8.0 266 | * 267 | * @return false|array `false` on failure; an array containing `location` 268 | * and `events` items on success. 269 | */ 270 | public function get_cached_events() { 271 | $cached_response = get_site_transient( $this->get_events_transient_key( $this->user_location ) ); 272 | $cached_response = $this->trim_events( $cached_response ); 273 | 274 | return $this->format_event_data_time( $cached_response ); 275 | } 276 | 277 | /** 278 | * Add formatted date and time items for each event in an API response 279 | * 280 | * This has to be called after the data is pulled from the cache, because 281 | * the cached events are shared by all users. If it was called before storing 282 | * the cache, then all users would see the events in the localized data/time 283 | * of the user who triggered the cache refresh, rather than their own. 284 | * 285 | * @access protected 286 | * @since 4.8.0 287 | * 288 | * @param array $response_body The response which contains the events. 289 | * @return array The response with dates and times formatted 290 | */ 291 | protected function format_event_data_time( $response_body ) { 292 | if ( isset( $response_body['events'] ) ) { 293 | foreach ( $response_body['events'] as $key => $event ) { 294 | $timestamp = strtotime( $event['date'] ); 295 | 296 | /* 297 | * It's important to keep the day of the week in the formatted date, 298 | * so that users can tell at a glance if the event is on a day they 299 | * are available, without having to open the link. 300 | */ 301 | /* translators: Date format for upcoming events on the dashboard. Include the day of the week. See https://secure.php.net/date. */ 302 | $response_body['events'][ $key ]['formatted_date'] = date_i18n( __( 'l, M j, Y', 'nearby-wp-events' ), $timestamp ); 303 | $response_body['events'][ $key ]['formatted_time'] = date_i18n( get_option( 'time_format' ), $timestamp ); 304 | } 305 | } 306 | 307 | return $response_body; 308 | } 309 | 310 | /** 311 | * Discard events that occurred more than 24 hours ago, then reduce the remaining list down to three items. 312 | * 313 | * @access protected 314 | * @since 4.8.0 315 | * 316 | * @param array $response_body The response body which contains the events. 317 | * @return array The response body with events trimmed. 318 | */ 319 | protected function trim_events( $response_body ) { 320 | if ( isset( $response_body['events'] ) ) { 321 | $current_timestamp = current_time('timestamp' ); 322 | 323 | foreach ( $response_body['events'] as $key => $event ) { 324 | // Skip WordCamps, because they might be multi-day events. 325 | if ( 'meetup' !== $event['type'] ) { 326 | continue; 327 | } 328 | 329 | $event_timestamp = strtotime( $event['date'] ); 330 | 331 | if ( $current_timestamp > $event_timestamp && ( $current_timestamp - $event_timestamp ) > DAY_IN_SECONDS ) { 332 | unset( $response_body['events'][ $key ] ); 333 | } 334 | } 335 | 336 | $response_body['events'] = array_slice( $response_body['events'], 0, 3 ); 337 | } 338 | 339 | return $response_body; 340 | } 341 | 342 | 343 | /** 344 | * Log responses to Events API requests 345 | * 346 | * All responses are logged when debugging, even if they're not WP_Errors. See 347 | * `WP_Nearby_Events::get_events()` for details. 348 | * 349 | * Errors are logged instead of being triggered, to avoid breaking the JSON 350 | * response when called from AJAX handlers and `display_errors` is enabled. 351 | * 352 | * Debugging info is still needed for "successful" responses, because 353 | * the API might have returned a different location than the one the user 354 | * intended to receive. In those cases, knowing the exact `request_url` is 355 | * critical. 356 | * 357 | * @access protected 358 | * @since 4.8.0 359 | * 360 | * @param string $message A description of what occurred 361 | * @param array $debugging_info Details that provide more context for the 362 | * log entry 363 | */ 364 | protected function maybe_log_events_response( $message, $details ) { 365 | if ( ! WP_DEBUG_LOG ) { 366 | return; 367 | } 368 | 369 | error_log( sprintf( 370 | '%s: %s. Details: %s', 371 | __METHOD__, 372 | trim( $message, '.' ), 373 | wp_json_encode( $details ) 374 | ) ); 375 | } 376 | } 377 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------