From 3dff686a00355519dbc79a356d835aef011605ef Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 10 Nov 2021 15:41:40 +0900 Subject: [PATCH] Clean up spaces, tabs, indentation, and bracket formatting --- assets/css/activation.css | 10 +- assets/css/admin.css | 104 +- assets/css/chosen.css | 6 +- assets/css/customize.css | 2 +- assets/css/equation.css | 2 +- assets/css/leaflet.css | 20 +- assets/css/menu.css | 2 +- assets/css/setup.css | 422 ++-- assets/css/slickmap.css | 2 +- assets/css/sportspress-style-ltr.css | 18 +- assets/css/sportspress-style-rtl.css | 18 +- assets/css/sportspress-style.css | 630 ++--- assets/css/sportspress.css | 32 +- assets/css/themes/twentyfourteen.css | 2 +- assets/js/admin/colorpicker.js | 56 +- assets/js/admin/dashboard.js | 25 +- assets/js/admin/editor-lang.php | 80 +- assets/js/admin/editor.js | 86 +- assets/js/admin/equationbuilder.js | 86 +- assets/js/admin/iconpicker.js | 79 +- assets/js/admin/quickeditor.js | 100 +- assets/js/admin/settings.js | 138 +- assets/js/admin/sp-geocoder.js | 122 +- assets/js/admin/sp-setup-geocoder.js | 122 +- assets/js/admin/sportspress-admin.js | 2050 ++++++++++------- assets/js/admin/sportspress-setup.js | 52 +- assets/js/admin/widgets.js | 91 +- assets/js/blocks/event-calendar.js | 161 +- assets/js/jquery.fitvids.js | 124 +- assets/js/sportspress.js | 211 +- feeds/ical.php | 106 +- .../abstracts/abstract-sp-custom-post.php | 22 +- .../abstracts/abstract-sp-secondary-post.php | 94 +- includes/admin/class-sp-admin-ajax.php | 12 +- includes/admin/class-sp-admin-assets.php | 217 +- includes/admin/class-sp-admin-dashboard.php | 222 +- includes/admin/class-sp-admin-editor.php | 12 +- includes/admin/class-sp-admin-importers.php | 298 +-- includes/admin/class-sp-admin-menus.php | 514 +++-- includes/admin/class-sp-admin-notices.php | 236 +- .../class-sp-admin-permalink-settings.php | 173 +- includes/admin/class-sp-admin-post-types.php | 184 +- includes/admin/class-sp-admin-sample-data.php | 417 ++-- includes/admin/class-sp-admin-settings.php | 1324 ++++++----- .../admin/class-sp-admin-setup-wizard.php | 1638 ++++++------- includes/admin/class-sp-admin-sports.php | 162 +- includes/admin/class-sp-admin-status.php | 103 +- includes/admin/class-sp-admin-taxonomies.php | 153 +- includes/admin/class-sp-admin-welcome.php | 707 +++--- includes/admin/class-sp-admin.php | 46 +- .../importers/class-sp-event-importer.php | 261 ++- .../class-sp-event-performance-importer.php | 109 +- .../importers/class-sp-fixture-importer.php | 170 +- .../admin/importers/class-sp-importer.php | 88 +- .../importers/class-sp-official-importer.php | 40 +- .../importers/class-sp-player-importer.php | 136 +- .../importers/class-sp-staff-importer.php | 98 +- .../importers/class-sp-team-importer.php | 65 +- .../class-sp-admin-cpt-calendar.php | 272 +-- .../post-types/class-sp-admin-cpt-column.php | 128 +- .../post-types/class-sp-admin-cpt-event.php | 595 ++--- .../post-types/class-sp-admin-cpt-list.php | 264 ++- .../post-types/class-sp-admin-cpt-metric.php | 104 +- .../class-sp-admin-cpt-official.php | 71 +- .../post-types/class-sp-admin-cpt-outcome.php | 114 +- .../class-sp-admin-cpt-performance.php | 132 +- .../post-types/class-sp-admin-cpt-player.php | 629 ++--- .../post-types/class-sp-admin-cpt-result.php | 104 +- .../post-types/class-sp-admin-cpt-spec.php | 104 +- .../post-types/class-sp-admin-cpt-staff.php | 287 +-- .../class-sp-admin-cpt-statistic.php | 128 +- .../post-types/class-sp-admin-cpt-table.php | 224 +- .../post-types/class-sp-admin-cpt-team.php | 235 +- .../admin/post-types/class-sp-admin-cpt.php | 110 +- .../post-types/class-sp-admin-meta-boxes.php | 296 +-- .../class-sp-meta-box-calendar-columns.php | 40 +- .../class-sp-meta-box-calendar-data.php | 140 +- .../class-sp-meta-box-calendar-details.php | 90 +- .../class-sp-meta-box-calendar-feeds.php | 16 +- .../class-sp-meta-box-calendar-format.php | 16 +- .../class-sp-meta-box-calendar-shortcode.php | 16 +- .../class-sp-meta-box-column-details.php | 42 +- .../class-sp-meta-box-column-equation.php | 17 +- .../meta-boxes/class-sp-meta-box-config.php | 20 +- .../meta-boxes/class-sp-meta-box-equation.php | 179 +- .../class-sp-meta-box-event-details.php | 38 +- .../class-sp-meta-box-event-format.php | 16 +- .../class-sp-meta-box-event-mode.php | 49 +- .../class-sp-meta-box-event-officials.php | 114 +- .../class-sp-meta-box-event-performance.php | 303 ++- .../class-sp-meta-box-event-results.php | 199 +- .../class-sp-meta-box-event-shortcode.php | 41 +- .../class-sp-meta-box-event-specs.php | 32 +- .../class-sp-meta-box-event-teams.php | 86 +- .../class-sp-meta-box-event-video.php | 24 +- .../class-sp-meta-box-list-columns.php | 21 +- .../class-sp-meta-box-list-data.php | 147 +- .../class-sp-meta-box-list-details.php | 90 +- .../class-sp-meta-box-list-format.php | 16 +- .../class-sp-meta-box-list-shortcode.php | 16 +- .../class-sp-meta-box-metric-details.php | 23 +- .../class-sp-meta-box-outcome-details.php | 53 +- .../class-sp-meta-box-performance-details.php | 59 +- ...class-sp-meta-box-performance-equation.php | 17 +- .../class-sp-meta-box-player-columns.php | 31 +- .../class-sp-meta-box-player-details.php | 195 +- .../class-sp-meta-box-player-metrics.php | 32 +- .../class-sp-meta-box-player-shortcode.php | 12 +- .../class-sp-meta-box-player-statistics.php | 188 +- .../class-sp-meta-box-result-details.php | 25 +- .../class-sp-meta-box-result-equation.php | 17 +- .../class-sp-meta-box-spec-details.php | 23 +- .../class-sp-meta-box-staff-details.php | 163 +- .../class-sp-meta-box-staff-shortcode.php | 12 +- .../class-sp-meta-box-statistic-details.php | 83 +- .../class-sp-meta-box-statistic-equation.php | 17 +- .../class-sp-meta-box-table-data.php | 117 +- .../class-sp-meta-box-table-details.php | 52 +- .../class-sp-meta-box-table-format.php | 16 +- .../class-sp-meta-box-table-mode.php | 51 +- .../class-sp-meta-box-table-shortcode.php | 16 +- .../class-sp-meta-box-team-columns.php | 56 +- .../class-sp-meta-box-team-details.php | 126 +- .../class-sp-meta-box-team-lists.php | 47 +- .../class-sp-meta-box-team-staff.php | 47 +- .../class-sp-meta-box-team-tables.php | 47 +- .../settings/class-sp-settings-events.php | 968 ++++---- .../settings/class-sp-settings-general.php | 744 +++--- .../settings/class-sp-settings-licenses.php | 324 +-- .../settings/class-sp-settings-modules.php | 163 +- .../admin/settings/class-sp-settings-page.php | 274 +-- .../settings/class-sp-settings-players.php | 367 +-- .../settings/class-sp-settings-staff.php | 184 +- .../settings/class-sp-settings-status.php | 571 +++-- .../settings/class-sp-settings-teams.php | 171 +- .../admin/settings/class-sp-settings-text.php | 119 +- includes/admin/sp-admin-functions.php | 95 +- includes/admin/views/html-admin-config.php | 252 +- .../admin/views/html-admin-page-status.php | 542 +++-- includes/admin/views/html-admin-settings.php | 21 +- includes/admin/views/html-notice-install.php | 24 +- .../admin/views/html-notice-no-access.php | 6 +- .../views/html-notice-template-check.php | 20 +- .../admin/views/html-notice-theme-support.php | 6 +- includes/api/class-sp-rest-api.php | 1709 +++++++------- .../api/class-sp-rest-posts-controller.php | 20 +- includes/class-sp-ajax.php | 530 ++--- includes/class-sp-calendar.php | 380 +-- includes/class-sp-countries.php | 499 ++-- includes/class-sp-event.php | 500 ++-- includes/class-sp-feeds.php | 26 +- includes/class-sp-formats.php | 51 +- includes/class-sp-frontend-scripts.php | 138 +- includes/class-sp-install.php | 1112 ++++----- includes/class-sp-league-table.php | 708 +++--- includes/class-sp-modules.php | 369 +-- includes/class-sp-player-list.php | 931 ++++---- includes/class-sp-player.php | 525 +++-- includes/class-sp-post-types.php | 893 +++---- includes/class-sp-shortcodes.php | 34 +- includes/class-sp-staff.php | 56 +- includes/class-sp-team.php | 500 ++-- includes/class-sp-template-loader.php | 136 +- includes/class-sp-templates.php | 442 ++-- includes/class-sp-wpml.php | 217 +- includes/libraries/class-eqeos.php | 337 +-- includes/libraries/class-phpstack.php | 43 +- .../libraries/class-tgm-plugin-activation.php | 48 +- .../class-sp-shortcode-countdown.php | 9 +- .../class-sp-shortcode-event-blocks.php | 9 +- .../class-sp-shortcode-event-calendar.php | 9 +- .../class-sp-shortcode-event-details.php | 9 +- .../class-sp-shortcode-event-full.php | 91 +- .../class-sp-shortcode-event-list.php | 9 +- .../class-sp-shortcode-event-officials.php | 9 +- .../class-sp-shortcode-event-performance.php | 9 +- .../class-sp-shortcode-event-results.php | 9 +- .../class-sp-shortcode-event-teams.php | 9 +- .../class-sp-shortcode-event-venue.php | 9 +- .../class-sp-shortcode-league-table.php | 9 +- .../class-sp-shortcode-player-details.php | 9 +- .../class-sp-shortcode-player-gallery.php | 9 +- .../class-sp-shortcode-player-list.php | 9 +- .../class-sp-shortcode-player-statistics.php | 9 +- .../class-sp-shortcode-staff-profile.php | 13 +- .../shortcodes/class-sp-shortcode-staff.php | 11 +- .../class-sp-shortcode-team-gallery.php | 9 +- includes/sp-api-functions.php | 121 +- includes/sp-conditional-functions.php | 51 +- includes/sp-core-functions.php | 1338 ++++++----- includes/sp-deprecated-functions.php | 34 +- includes/sp-formatting-functions.php | 165 +- includes/sp-option-filters.php | 27 +- includes/sp-template-functions.php | 149 +- includes/sp-template-hooks.php | 214 +- .../widgets/class-sp-widget-birthdays.php | 71 +- .../widgets/class-sp-widget-countdown.php | 211 +- .../widgets/class-sp-widget-event-blocks.php | 223 +- .../class-sp-widget-event-calendar.php | 184 +- .../widgets/class-sp-widget-event-list.php | 249 +- .../widgets/class-sp-widget-league-table.php | 153 +- .../class-sp-widget-player-gallery.php | 168 +- .../widgets/class-sp-widget-player-list.php | 214 +- includes/widgets/class-sp-widget-staff.php | 52 +- .../widgets/class-sp-widget-team-gallery.php | 134 +- index.php | 2 +- modules/sportspress-admin-bar.php | 93 +- modules/sportspress-birthdays.php | 374 +-- modules/sportspress-bulk-actions.php | 325 +-- modules/sportspress-calendars.php | 870 +++---- .../sportspress-comments-scheduled-events.php | 249 +- modules/sportspress-conditional-equations.php | 244 +- modules/sportspress-countdowns.php | 207 +- modules/sportspress-default-nationality.php | 99 +- modules/sportspress-event-specs.php | 438 ++-- modules/sportspress-event-status.php | 182 +- modules/sportspress-event-videos.php | 97 +- modules/sportspress-gutenberg.php | 154 +- modules/sportspress-icons.php | 345 +-- modules/sportspress-importers.php | 71 +- modules/sportspress-lazy-loading.php | 447 ++-- modules/sportspress-league-tables.php | 604 ++--- modules/sportspress-next-team-preset.php | 297 +-- modules/sportspress-officials.php | 990 ++++---- modules/sportspress-openstreetmap.php | 299 +-- modules/sportspress-overview.php | 988 ++++++-- modules/sportspress-player-assignments.php | 335 +-- modules/sportspress-player-lists.php | 609 ++--- modules/sportspress-styles.php | 292 +-- modules/sportspress-template-selector.php | 330 +-- modules/sportspress-tutorials.php | 363 +-- modules/sportspress-user-registration.php | 336 +-- modules/sportspress-widget-alignment.php | 237 +- modules/sportspress-widgets.php | 81 +- modules/sportspress-wordpay.php | 344 +-- sportspress.php | 787 +++---- templates/birthdays.php | 149 +- templates/countdown.php | 166 +- templates/event-blocks.php | 256 +- templates/event-calendar.php | 251 +- templates/event-details.php | 61 +- templates/event-fixtures-results.php | 105 +- templates/event-list.php | 548 +++-- templates/event-logos-block.php | 20 +- templates/event-logos-inline.php | 18 +- templates/event-logos.php | 50 +- templates/event-officials-list.php | 14 +- templates/event-officials-table.php | 10 +- templates/event-officials.php | 47 +- templates/event-overview.php | 10 +- templates/event-performance-table.php | 231 +- templates/event-performance.php | 278 ++- templates/event-results.php | 69 +- templates/event-staff.php | 36 +- templates/event-venue.php | 27 +- templates/event-video.php | 23 +- templates/league-table.php | 138 +- templates/official-details.php | 88 +- templates/player-details.php | 88 +- templates/player-events.php | 27 +- templates/player-gallery-thumbnail.php | 30 +- templates/player-gallery.php | 190 +- templates/player-list.php | 347 +-- templates/player-photo.php | 19 +- templates/player-selector.php | 57 +- templates/player-statistics-league.php | 21 +- templates/player-statistics.php | 73 +- templates/post-excerpt.php | 15 +- templates/staff-content.php | 31 +- templates/staff-details.php | 58 +- templates/staff-excerpt.php | 31 +- templates/staff-header.php | 30 +- templates/staff-photo.php | 19 +- templates/staff-selector.php | 53 +- templates/team-details.php | 33 +- templates/team-events.php | 26 +- templates/team-gallery-thumbnail.php | 27 +- templates/team-gallery.php | 113 +- templates/team-link.php | 26 +- templates/team-lists.php | 24 +- templates/team-logo.php | 19 +- templates/team-staff.php | 27 +- templates/team-tables.php | 27 +- templates/venue-map.php | 55 +- uninstall.php | 13 +- 285 files changed, 29638 insertions(+), 24147 deletions(-) diff --git a/assets/css/activation.css b/assets/css/activation.css index 8c8854d2..2839d1aa 100644 --- a/assets/css/activation.css +++ b/assets/css/activation.css @@ -60,18 +60,18 @@ p.sportspress-actions a.button-primary:focus { .sportspress-steps:before, .sportspress-steps:after { - content: " "; - display: table; + content: " "; + display: table; } .sportspress-steps:after { - clear: both; + clear: both; } .sportspress-steps { - *zoom: 1; + *zoom: 1; } .sportspress-steps .welcome-icon i:before { color: #888; -} \ No newline at end of file +} diff --git a/assets/css/admin.css b/assets/css/admin.css index ada2c019..798cdc8a 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -318,8 +318,8 @@ table.widefat.sp-data-table input[type="text"], table.widefat.sp-data-table input[type="number"] { min-width: 1.25em; width: 100%; - margin: 1px; - padding: 3px 5px; + margin: 1px; + padding: 3px 5px; } table.widefat.sp-data-table input[type="text"]::placeholder, @@ -681,28 +681,28 @@ table.widefat.sp-sortable-table tbody tr .icon { .sp-toggle-switch + label:before, .sp-toggle-switch + label:after { - display: block; - position: absolute; - top: 0; - left: 0; - bottom: 0; - content: ""; + display: block; + position: absolute; + top: 0; + left: 0; + bottom: 0; + content: ""; } .sp-toggle-switch + label:before { - right: 1px; - background-color: #e4e4e4; - border-radius: 16px; - transition: background 0.4s; + right: 1px; + background-color: #e4e4e4; + border-radius: 16px; + transition: background 0.4s; } .sp-toggle-switch + label:after { - width: 16px; - background-color: #fff; - border-radius: 100%; - -webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); - transition: margin 0.4s; + width: 16px; + background-color: #fff; + border-radius: 100%; + -webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); + transition: margin 0.4s; } .sp-toggle-switch:checked + label:before { @@ -735,7 +735,7 @@ table.widefat.sp-sortable-table tbody tr .icon { clear: both; max-width: 382px; width: 100%; - box-sizing: border-box; + box-sizing: border-box; } .sp-sortable-list .sp-item-float + .sp-item-float { @@ -743,49 +743,49 @@ table.widefat.sp-sortable-table tbody tr .icon { } .sp-item-bar { - clear: both; - line-height: 1.5em; - position: relative; - margin: 9px 0 0; + clear: both; + line-height: 1.5em; + position: relative; + margin: 9px 0 0; } .sp-item-bar .sp-item-handle { background: #fafafa; color: #23282d; - border: 1px solid #dfdfdf; - position: relative; - padding: 10px 15px; - height: auto; - min-height: 20px; - line-height: 30px; - overflow: hidden; - word-wrap: break-word; + border: 1px solid #dfdfdf; + position: relative; + padding: 10px 15px; + height: auto; + min-height: 20px; + line-height: 30px; + overflow: hidden; + word-wrap: break-word; } .sp-item-bar .sp-item-handle:hover { - border-color: #999; - -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.1); - box-shadow: 0 1px 2px rgba(0,0,0,.1); + border-color: #999; + -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.1); + box-shadow: 0 1px 2px rgba(0,0,0,.1); } .sp-item-bar .sp-item-title { font-size: 13px; - font-weight: 600; - line-height: 20px; - display: block; - margin-right: 13em; + font-weight: 600; + line-height: 20px; + display: block; + margin-right: 13em; } .sp-item-settings { - display: block; - padding: 10px 0 10px 15px; - position: relative; - z-index: 10; - background: #fff; - border: 1px solid #e5e5e5; - border-top: none; - -webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04); - box-shadow: 0 1px 1px rgba(0,0,0,.04); + display: block; + padding: 10px 0 10px 15px; + position: relative; + z-index: 10; + background: #fff; + border: 1px solid #e5e5e5; + border-top: none; + -webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04); + box-shadow: 0 1px 1px rgba(0,0,0,.04); } .js .sp-item-handle { @@ -793,9 +793,9 @@ table.widefat.sp-sortable-table tbody tr .icon { } .sp-sortable-list .sp-item-placeholder { - border: 1px dashed #b4b9be; - margin: 9px auto 6px; - height: 42px; + border: 1px dashed #b4b9be; + margin: 9px auto 6px; + height: 42px; } /* Logo */ @@ -1225,7 +1225,7 @@ table.sp-status-table td mark.yes { float: none; margin-left: 0; } - + .wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_format, .wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_icon, .wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_number { @@ -1241,7 +1241,7 @@ table.sp-status-table td mark.yes { margin-right: 0; padding-right: 0; } - + .about-sportspress-wrap .sp-badge { float: none; margin: 20px auto 10px; diff --git a/assets/css/chosen.css b/assets/css/chosen.css index 45fee21c..c7cac737 100755 --- a/assets/css/chosen.css +++ b/assets/css/chosen.css @@ -427,9 +427,9 @@ This file is generated by `grunt build`, do not edit it by hand. .chosen-container-multi .chosen-choices .search-choice .search-choice-close, .chosen-container .chosen-results-scroll-down span, .chosen-container .chosen-results-scroll-up span { - background-image: url('../images/chosen/chosen-sprite@2x.png') !important; - background-size: 52px 37px !important; - background-repeat: no-repeat !important; + background-image: url('../images/chosen/chosen-sprite@2x.png') !important; + background-size: 52px 37px !important; + background-repeat: no-repeat !important; } } /* @end */ diff --git a/assets/css/customize.css b/assets/css/customize.css index 96c6560f..2852b55c 100644 --- a/assets/css/customize.css +++ b/assets/css/customize.css @@ -17,4 +17,4 @@ } #available-widgets [class*=sp_countdown] .widget-title:before { content: "\f469"; -} \ No newline at end of file +} diff --git a/assets/css/equation.css b/assets/css/equation.css index 37536d68..c9361b02 100644 --- a/assets/css/equation.css +++ b/assets/css/equation.css @@ -73,4 +73,4 @@ .sp-equation-formula .button .remove:hover { color: #d00; -} \ No newline at end of file +} diff --git a/assets/css/leaflet.css b/assets/css/leaflet.css index 017fa0e4..0791c008 100644 --- a/assets/css/leaflet.css +++ b/assets/css/leaflet.css @@ -22,7 +22,7 @@ .leaflet-marker-shadow { -webkit-user-select: none; -moz-user-select: none; - user-select: none; + user-select: none; -webkit-user-drag: none; } /* Prevents IE11 from highlighting tiles in blue */ @@ -86,7 +86,7 @@ width: 0; height: 0; -moz-box-sizing: border-box; - box-sizing: border-box; + box-sizing: border-box; z-index: 800; } /* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */ @@ -173,15 +173,15 @@ opacity: 0; -webkit-transition: opacity 0.2s linear; -moz-transition: opacity 0.2s linear; - transition: opacity 0.2s linear; + transition: opacity 0.2s linear; } .leaflet-fade-anim .leaflet-map-pane .leaflet-popup { opacity: 1; } .leaflet-zoom-animated { -webkit-transform-origin: 0 0; - -ms-transform-origin: 0 0; - transform-origin: 0 0; + -ms-transform-origin: 0 0; + transform-origin: 0 0; } .leaflet-zoom-anim .leaflet-zoom-animated { will-change: transform; @@ -189,13 +189,13 @@ .leaflet-zoom-anim .leaflet-zoom-animated { -webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1); -moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1); - transition: transform 0.25s cubic-bezier(0,0,0.25,1); + transition: transform 0.25s cubic-bezier(0,0,0.25,1); } .leaflet-zoom-anim .leaflet-tile, .leaflet-pan-anim .leaflet-tile { -webkit-transition: none; -moz-transition: none; - transition: none; + transition: none; } .leaflet-zoom-anim .leaflet-zoom-hide { @@ -435,7 +435,7 @@ svg.leaflet-image-layer.leaflet-interactive path { white-space: nowrap; overflow: hidden; -moz-box-sizing: border-box; - box-sizing: border-box; + box-sizing: border-box; background: #fff; background: rgba(255, 255, 255, 0.5); @@ -498,8 +498,8 @@ svg.leaflet-image-layer.leaflet-interactive path { -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); - -ms-transform: rotate(45deg); - transform: rotate(45deg); + -ms-transform: rotate(45deg); + transform: rotate(45deg); } .leaflet-popup-content-wrapper, .leaflet-popup-tip { diff --git a/assets/css/menu.css b/assets/css/menu.css index 9e11a486..c8cf53e9 100644 --- a/assets/css/menu.css +++ b/assets/css/menu.css @@ -371,4 +371,4 @@ i.mce-i-sp_shortcodes_button:before, span.mce_sp_shortcodes_button:before { text-align: center; content: "\f111"; font-size: 20px; -} \ No newline at end of file +} diff --git a/assets/css/setup.css b/assets/css/setup.css index eec50dc6..178efe78 100644 --- a/assets/css/setup.css +++ b/assets/css/setup.css @@ -1,421 +1,421 @@ .sp-setup-content p, .sp-setup-content table { - font-size: 1em; - line-height: 1.75em; - color: #666; + font-size: 1em; + line-height: 1.75em; + color: #666; } body { - margin: 100px auto 24px; - box-shadow: none; - background: #f1f1f1; - padding: 0; + margin: 100px auto 24px; + box-shadow: none; + background: #f1f1f1; + padding: 0; } #sp-logo { - border: 0; - margin: 24px 0; - padding: 0; - text-align: center; + border: 0; + margin: 24px 0; + padding: 0; + text-align: center; } #sp-logo img { - width: auto; - height: auto; - max-width: 100%; - max-height: 50px; + width: auto; + height: auto; + max-width: 100%; + max-height: 50px; } .sp-setup-content { - box-shadow: 0 1px 3px rgba(0, 0, 0, .13); - padding: 24px 24px 0; - background: #fff; - zoom: 1; + box-shadow: 0 1px 3px rgba(0, 0, 0, .13); + padding: 24px 24px 0; + background: #fff; + zoom: 1; } .sp-setup-content:after { - content: ""; - display: table; - clear: both; + content: ""; + display: table; + clear: both; } .sp-setup-content h1, .sp-setup-content h2, .sp-setup-content h3, .sp-setup-content table { - margin: 0 0 24px; - border: 0; - padding: 0; - color: #666; - clear: none; + margin: 0 0 24px; + border: 0; + padding: 0; + color: #666; + clear: none; } .sp-setup-content p { - margin: 0 0 24px; + margin: 0 0 24px; } .sp-setup-content a { - color: #00a69c; + color: #00a69c; } .sp-setup-content a:focus, .sp-setup-content a:hover { - color: #111; + color: #111; } .sp-setup-content .form-table { - width: 100%; - border-top: 1px solid #eee; + width: 100%; + border-top: 1px solid #eee; } .sp-setup-content .form-table th { - width: 30%; - vertical-align: top; - font-weight: 700; + width: 30%; + vertical-align: top; + font-weight: 700; } .sp-setup-content .form-table td { - vertical-align: top; + vertical-align: top; } .sp-setup-content .form-table td input, .sp-setup-content .form-table td select { - width: 100%; - box-sizing: border-box; + width: 100%; + box-sizing: border-box; } .sp-setup-content .form-table td input[size] { - width: auto; + width: auto; } .sp-setup-content .form-table td ol, .sp-setup-content .form-table td ul { - margin: 0; - padding: 0; + margin: 0; + padding: 0; } .sp-setup-content .form-table td ul { - list-style: none; + list-style: none; } .sp-setup-content .form-table td li { - margin-bottom: 10px; + margin-bottom: 10px; } .sp-setup-content .form-table td li:last-child { - margin-bottom: 0; + margin-bottom: 0; } .sp-setup-content .form-table td .description { - line-height: 1.5em; - display: block; - margin: .25em 0 0; - color: #999; - font-style: italic; + line-height: 1.5em; + display: block; + margin: .25em 0 0; + color: #999; + font-style: italic; } .sp-setup-content .form-table td .input-checkbox, .sp-setup-content .form-table td .input-radio { - width: auto; - box-sizing: inherit; - padding: inherit; - margin: 0 .5em 0 0; - box-shadow: none; + width: auto; + box-sizing: inherit; + padding: inherit; + margin: 0 .5em 0 0; + box-shadow: none; } .sp-setup-content .form-table .section_title td { - padding: 0; + padding: 0; } .sp-setup-content .form-table .section_title td h2, .sp-setup-content .form-table .section_title td p { - margin: 12px 0 0; + margin: 12px 0 0; } .sp-setup-content .form-table td, .sp-setup-content .form-table th { - padding: 14px 0; - margin: 0; - border: 0; - border-bottom: 1px solid #eee; + padding: 14px 0; + margin: 0; + border: 0; + border-bottom: 1px solid #eee; } .sp-setup-content .form-table td:first-child, .sp-setup-content .form-table th:first-child { - padding-right: 9px; + padding-right: 9px; } .sp-setup-content .form-table th .sp-desc-tip { - line-height: 1.4; + line-height: 1.4; } .sp-setup-content .form-table .sp-chosen-container { - display: block; + display: block; } .sp-setup-content .form-table .sp-location-picker { - width: 100%; - height: 320px; - margin: 0.5em 0 0; + width: 100%; + height: 320px; + margin: 0.5em 0 0; } .sp-setup-content .twitter-share-button { - float: right; + float: right; } .sp-setup-content .sp-banner { - margin: 0 -24px 24px; + margin: 0 -24px 24px; } .sp-setup-content .sp-banner img { - display: block; - width: auto; - height: auto; - max-width: 100%; + display: block; + width: auto; + height: auto; + max-width: 100%; } .sp-setup-content .sp-setup-next-steps { - overflow: hidden; - margin: 0 0 24px; + overflow: hidden; + margin: 0 0 24px; } .sp-setup-content .sp-setup-next-steps h2 { - margin-bottom: 12px; + margin-bottom: 12px; } .sp-setup-content .sp-setup-next-steps .sp-setup-next-steps-first { - float: left; - width: 50%; - box-sizing: border-box; + float: left; + width: 50%; + box-sizing: border-box; } .sp-setup-content .sp-setup-next-steps .sp-setup-next-steps-last { - float: right; - width: 50%; - box-sizing: border-box; + float: right; + width: 50%; + box-sizing: border-box; } .sp-setup-content .sp-setup-next-steps ul { - padding: 0 2em 0 0; - list-style: none; - margin: 0; + padding: 0 2em 0 0; + list-style: none; + margin: 0; } .sp-setup-content .sp-setup-next-steps ul li .button { - display: block; - padding: 0 0 .75em; + display: block; + padding: 0 0 .75em; } .sp-setup-content .sp-setup-next-steps ul li .button-first-event { - background-color: #3bbab3; - border-color: #15a29a; - -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; - box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; - text-shadow: 0 -1px 1px #15a29a, 1px 0 1px #15a29a, 0 1px 1px #15a29a, -1px 0 1px #15a29a; - font-size: 1em; - height: auto; - line-height: 1.75em; - margin: 0 0 .75em; - opacity: 1; - padding: 1em; - text-align: center; + background-color: #3bbab3; + border-color: #15a29a; + -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; + text-shadow: 0 -1px 1px #15a29a, 1px 0 1px #15a29a, 0 1px 1px #15a29a, -1px 0 1px #15a29a; + font-size: 1em; + height: auto; + line-height: 1.75em; + margin: 0 0 .75em; + opacity: 1; + padding: 1em; + text-align: center; } .sp-setup-content .sp-setup-next-steps ul li .button-first-event:active, .sp-setup-content .sp-setup-next-steps ul li .button-first-event:focus, .sp-setup-content .sp-setup-next-steps ul li .button-first-event:hover { - background: #15a29a; - border-color: #15a29a; - -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; - box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; + background: #15a29a; + border-color: #15a29a; + -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; } .sp-setup-content .sp-setup-next-steps ul li a:before { - color: #82878c; - font: 400 20px/1 dashicons; - speak: none; - display: inline-block; - padding: 0 10px 0 0; - top: 1px; - position: relative; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - text-decoration: none!important; - vertical-align: top; + color: #82878c; + font: 400 20px/1 dashicons; + speak: none; + display: inline-block; + padding: 0 10px 0 0; + top: 1px; + position: relative; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + text-decoration: none!important; + vertical-align: top; } .sp-setup-content .sp-setup-next-steps ul .learn-more a:before { - content: "\f105"; + content: "\f105"; } .sp-setup-content .sp-setup-next-steps ul .video-walkthrough a:before { - content: "\f126"; + content: "\f126"; } .sp-setup-content .sp-setup-next-steps ul .newsletter a:before { - content: "\f465"; + content: "\f465"; } .sp-setup-content .updated { - padding: 24px 24px 0; - margin: 0 0 24px; - overflow: hidden; - background: #f5f5f5; + padding: 24px 24px 0; + margin: 0 0 24px; + overflow: hidden; + background: #f5f5f5; } .sp-setup-content .updated p { - padding: 0; - margin: 0 0 12px; + padding: 0; + margin: 0 0 12px; } .sp-setup-content .updated p:last-child { - margin: 0 0 24px; + margin: 0 0 24px; } .sp-setup-steps { - padding: 0 0 24px; - margin: 0; - list-style: none; - overflow: hidden; - color: #ccc; - width: 100%; - display: -webkit-inline-flex; - display: -ms-inline-flexbox; - display: inline-flex; + padding: 0 0 24px; + margin: 0; + list-style: none; + overflow: hidden; + color: #ccc; + width: 100%; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; } .sp-setup-steps li { - width: 20%; - float: left; - padding: 0 0 .8em; - margin: 0; - text-align: center; - position: relative; - border-bottom: 4px solid #ccc; - line-height: 1.4em; + width: 20%; + float: left; + padding: 0 0 .8em; + margin: 0; + text-align: center; + position: relative; + border-bottom: 4px solid #ccc; + line-height: 1.4em; } .sp-setup-steps li:before { - content: ""; - border: 4px solid #ccc; - border-radius: 100%; - width: 4px; - height: 4px; - position: absolute; - bottom: 0; - left: 50%; - margin-left: -6px; - margin-bottom: -8px; - background: #fff; + content: ""; + border: 4px solid #ccc; + border-radius: 100%; + width: 4px; + height: 4px; + position: absolute; + bottom: 0; + left: 50%; + margin-left: -6px; + margin-bottom: -8px; + background: #fff; } .sp-setup-steps li.active { - border-color: #00a69c; - color: #00a69c; + border-color: #00a69c; + color: #00a69c; } .sp-setup-steps li.active:before { - border-color: #00a69c; + border-color: #00a69c; } .sp-setup-steps li.done { - border-color: #00a69c; - color: #00a69c; + border-color: #00a69c; + color: #00a69c; } .sp-setup-steps li.done:before { - border-color: #00a69c; - background: #00a69c; + border-color: #00a69c; + background: #00a69c; } .sp-setup .sp-setup-actions:after { - content: ""; - display: table; - clear: both; + content: ""; + display: table; + clear: both; } .sp-setup .sp-setup-actions .button { - float: right; - font-size: 1.25em; - padding: .5em 1em; - line-height: 1em; - margin-right: .5em; - margin-bottom: 2px; - height: auto; - border-radius: 4px; + float: right; + font-size: 1.25em; + padding: .5em 1em; + line-height: 1em; + margin-right: .5em; + margin-bottom: 2px; + height: auto; + border-radius: 4px; } .sp-setup .sp-setup-actions .button-primary { - background-color: #3bbab3; - border-color: #15a29a; - -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; - box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; - text-shadow: 0 -1px 1px #15a29a, 1px 0 1px #15a29a, 0 1px 1px #15a29a, -1px 0 1px #15a29a; - float: right; - margin: 0 0 0 1em; - opacity: 1; + background-color: #3bbab3; + border-color: #15a29a; + -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; + text-shadow: 0 -1px 1px #15a29a, 1px 0 1px #15a29a, 0 1px 1px #15a29a, -1px 0 1px #15a29a; + float: right; + margin: 0 0 0 1em; + opacity: 1; } .sp-setup .sp-setup-actions .button-primary:active, .sp-setup .sp-setup-actions .button-primary:focus, .sp-setup .sp-setup-actions .button-primary:hover { - background: #15a29a; - border-color: #15a29a; - -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; - box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; + background: #15a29a; + border-color: #15a29a; + -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; } .sp-setup .sp-setup-actions .button-muted { - border: none; - background: transparent; - -webkit-box-shadow: none; - box-shadow: none; - padding: 0; - margin: .55em 0.05em 0.65em; - color: #ccc; + border: none; + background: transparent; + -webkit-box-shadow: none; + box-shadow: none; + padding: 0; + margin: .55em 0.05em 0.65em; + color: #ccc; } .sp-setup .sp-setup-actions .button-muted:hover { - color: #999; + color: #999; } .sp-return-to-dashboard { - font-size: .85em; - margin: 1.18em 0; - display: block; - text-align: center; + font-size: .85em; + margin: 1.18em 0; + display: block; + text-align: center; } .sp-return-to-dashboard a { - color: #b5b5b5; + color: #b5b5b5; } .sp-return-to-dashboard a:hover { - color: #888; + color: #888; } /* Media Queries */ @media screen and (max-width: 782px) { - .sp-setup-content .form-table tbody th { - width: auto - }; + .sp-setup-content .form-table tbody th { + width: auto + }; } @media screen and (min-width: 783px) { - .sp-setup-content .form-table td li input { - width: 40%; - } + .sp-setup-content .form-table td li input { + width: 40%; + } - .sp-setup-content .form-table td .player input { - width: 40%; - } + .sp-setup-content .form-table td .player input { + width: 40%; + } - .sp-setup-content .form-table td .player .player-number { - width: 11%; - } + .sp-setup-content .form-table td .player .player-number { + width: 11%; + } - .sp-setup-content .form-table td .staff .staff-name { - width: 52%; - } -} \ No newline at end of file + .sp-setup-content .form-table td .staff .staff-name { + width: 52%; + } +} diff --git a/assets/css/slickmap.css b/assets/css/slickmap.css index dd5a3649..b3c479d6 100644 --- a/assets/css/slickmap.css +++ b/assets/css/slickmap.css @@ -240,4 +240,4 @@ table, .sp-sitemap caption, .sp-sitemap tbody, .sp-sitemap tfoot, .sp-sitemap th .sp-sitemap .sp-utility { max-width: none; } -} \ No newline at end of file +} diff --git a/assets/css/sportspress-style-ltr.css b/assets/css/sportspress-style-ltr.css index a88b3168..7cf31c8a 100644 --- a/assets/css/sportspress-style-ltr.css +++ b/assets/css/sportspress-style-ltr.css @@ -6,28 +6,28 @@ */ .sp-tournament-bracket .sp-team .sp-team-name:before { - border-left-color: #e5e5e5 !important; - border-right-color: #e5e5e5 !important; - left: -10px !important; + border-left-color: #e5e5e5 !important; + border-right-color: #e5e5e5 !important; + left: -10px !important; } .sp-tournament-bracket .sp-team-flip .sp-team-name:before { - left: auto !important; - right: -10px !important; + left: auto !important; + right: -10px !important; } .sp-tournament-bracket .sp-team.sp-first-round .sp-team-name { - margin-left: -1px !important; + margin-left: -1px !important; } .sp-tournament-bracket .sp-team.sp-last-round .sp-team-name { - margin-right: -1px !important; + margin-right: -1px !important; } .sp-template-event-performance-icons .sp-performance-icons { - text-align: right !important; + text-align: right !important; } .sp-data-table .data-name { - text-align: left !important; + text-align: left !important; } diff --git a/assets/css/sportspress-style-rtl.css b/assets/css/sportspress-style-rtl.css index 1361a584..05850408 100644 --- a/assets/css/sportspress-style-rtl.css +++ b/assets/css/sportspress-style-rtl.css @@ -6,28 +6,28 @@ */ .sp-tournament-bracket .sp-team .sp-team-name:before { - border-right-color: #e5e5e5 !important; - border-left-color: #e5e5e5 !important; - right: -10px !important; + border-right-color: #e5e5e5 !important; + border-left-color: #e5e5e5 !important; + right: -10px !important; } .sp-tournament-bracket .sp-team-flip .sp-team-name:before { - right: auto !important; - left: -10px !important; + right: auto !important; + left: -10px !important; } .sp-tournament-bracket .sp-team.sp-first-round .sp-team-name { - margin-right: -1px !important; + margin-right: -1px !important; } .sp-tournament-bracket .sp-team.sp-last-round .sp-team-name { - margin-left: -1px !important; + margin-left: -1px !important; } .sp-template-event-performance-icons .sp-performance-icons { - text-align: left !important; + text-align: left !important; } .sp-data-table .data-name { - text-align: right !important; + text-align: right !important; } diff --git a/assets/css/sportspress-style.css b/assets/css/sportspress-style.css index 46922dc1..90de8f88 100644 --- a/assets/css/sportspress-style.css +++ b/assets/css/sportspress-style.css @@ -3,12 +3,12 @@ .sp-template, .sp-data-table, .sp-table-caption { - font-family: "Roboto", "Helvetica", sans-serif; + font-family: "Roboto", "Helvetica", sans-serif; } .sp-template { - clear: both; - overflow: hidden; + clear: both; + overflow: hidden; } /* @@ -34,34 +34,34 @@ .sp-table-caption h4, .sp-table-caption h5, .sp-table-caption h6 { - font-family: "Roboto", "Helvetica", sans-serif !important; + font-family: "Roboto", "Helvetica", sans-serif !important; } .sp-template { - margin-bottom: 20px !important; + margin-bottom: 20px !important; } .sp-template *, .sp-data-table *, .sp-table-caption { - box-sizing: border-box !important; - font-weight: 400 !important; - text-transform: none !important; - letter-spacing: normal !important; - color: #333 !important; + box-sizing: border-box !important; + font-weight: 400 !important; + text-transform: none !important; + letter-spacing: normal !important; + color: #333 !important; } .sp-table-caption { - margin: 0 !important; - padding: 15px !important; - background: #fff !important; - border: 1px solid #e5e5e5 !important; - border-bottom: none !important; - font-size: 20px !important; - font-weight: 400 !important; - line-height: 1.5 !important; - display: table !important; - width: 100% !important; + margin: 0 !important; + padding: 15px !important; + background: #fff !important; + border: 1px solid #e5e5e5 !important; + border-bottom: none !important; + font-size: 20px !important; + font-weight: 400 !important; + line-height: 1.5 !important; + display: table !important; + width: 100% !important; } /* Color Resets */ @@ -70,177 +70,177 @@ .sp-data-table input, .sp-template .sp-event-logos, .sp-template .sp-event-staff { - color: initial !important; + color: initial !important; } /* Links */ .sp-template a, .sp-data-table a { - box-shadow: none !important; - border: none !important; - text-decoration: none !important; - font-weight: inherit !important; - color: #00a69c !important; + box-shadow: none !important; + border: none !important; + text-decoration: none !important; + font-weight: inherit !important; + color: #00a69c !important; } .sp-template a:hover, .sp-data-table a:hover { - text-decoration: underline !important; + text-decoration: underline !important; } .sp-template a:hover .dashicons, .sp-template a:hover [class^="sp-icon-"], [class*=" sp-icon-"], .sp-data-table a:hover .dashicons, .sp-data-table a:hover [class^="sp-icon-"], [class*=" sp-icon-"] { - text-decoration: none !important; + text-decoration: none !important; } .sp-view-all-link { - padding: 10px 15px !important; - margin: 0 !important; - background: #fff !important; - border: 1px solid #e5e5e5 !important; - border-top: none !important; - overflow: hidden !important; - display: table !important; - width: 100% !important; - text-align: right !important; + padding: 10px 15px !important; + margin: 0 !important; + background: #fff !important; + border: 1px solid #e5e5e5 !important; + border-top: none !important; + overflow: hidden !important; + display: table !important; + width: 100% !important; + text-align: right !important; } .sp-view-all-link a { - font-size: 12px !important; - font-weight: 400 !important; - line-height: 1.5 !important; - text-decoration: none !important; - color: rgba(51,51,51,0.5) !important; + font-size: 12px !important; + font-weight: 400 !important; + line-height: 1.5 !important; + text-decoration: none !important; + color: rgba(51,51,51,0.5) !important; } .sp-view-all-link a:hover { - color: #333 !important; - text-decoration: none !important; + color: #333 !important; + text-decoration: none !important; } .sp-form-events a:hover { - color: #fff !important; - text-decoration: none !important; + color: #fff !important; + text-decoration: none !important; } /* Images */ .sp-template img { - display: inline-block !important; - box-shadow: none !important; + display: inline-block !important; + box-shadow: none !important; } /* Tables */ .sp-data-table { - margin: 0 !important; - background: #fff !important; - border-collapse: collapse !important; - border: 1px solid #e5e5e5 !important; - width: 100% !important; + margin: 0 !important; + background: #fff !important; + border-collapse: collapse !important; + border: 1px solid #e5e5e5 !important; + width: 100% !important; } .sp-data-table tr { - border: none !important; + border: none !important; } .sp-data-table th, .sp-data-table td { - font-size: 13px !important; - font-weight: 400 !important; - line-height: 1.5 !important; - border: 1px solid #e5e5e5 !important; - padding: 5px 10px !important; - text-align: center !important; + font-size: 13px !important; + font-weight: 400 !important; + line-height: 1.5 !important; + border: 1px solid #e5e5e5 !important; + padding: 5px 10px !important; + text-align: center !important; } .sp-data-table th { - font-size: 12px !important; - font-weight: 500 !important; - background: #fff !important; - color: #999 !important; - border: none !important; + font-size: 12px !important; + font-weight: 500 !important; + background: #fff !important; + color: #999 !important; + border: none !important; } .sp-data-table th a { - color: inherit !important; + color: inherit !important; } .sp-data-table .sp-highlight, .sp-data-table .highlighted td { - font-weight: 500 !important; - background: #f9f9f9 !important; + font-weight: 500 !important; + background: #f9f9f9 !important; } /* Galleries */ .sp-template-gallery .sp-gallery-wrapper { - border: 1px solid #e5e5e5 !important; - background: #fff !important; - display: table !important; - width: 100% !important; + border: 1px solid #e5e5e5 !important; + background: #fff !important; + display: table !important; + width: 100% !important; } .sp-template-gallery .gallery-item { - padding: 0 !important; - margin: 0 !important; - position: relative !important; + padding: 0 !important; + margin: 0 !important; + position: relative !important; } .sp-template-gallery .gallery-item a { - display: block !important; - color: #999 !important; + display: block !important; + color: #999 !important; } .sp-template-gallery .gallery-item img { - display: block !important; - border: none !important; - padding: 0 !important; - margin: 0 !important; - border-radius: 0 !important; + display: block !important; + border: none !important; + padding: 0 !important; + margin: 0 !important; + border-radius: 0 !important; } .sp-template-gallery .gallery-caption { - padding: 0 !important; - margin: 0 !important; - font-size: 12px !important; - font-style: normal !important; - font-weight: 500 !important; - text-align: center !important; - color: #999 !important; - line-height: 1.5 !important; - padding: 5px 10px !important; + padding: 0 !important; + margin: 0 !important; + font-size: 12px !important; + font-style: normal !important; + font-weight: 500 !important; + text-align: center !important; + color: #999 !important; + line-height: 1.5 !important; + padding: 5px 10px !important; } .sp-template-gallery .gallery-caption strong { - color: #fff !important; - background: #00a69c !important; - display: block !important; - font-weight: 400 !important; - font-size: 13px !important; - line-height: 1.5 !important; - position: absolute !important; - left: 0 !important; - top: 0 !important; - padding: 5px 10px !important; + color: #fff !important; + background: #00a69c !important; + display: block !important; + font-weight: 400 !important; + font-size: 13px !important; + line-height: 1.5 !important; + position: absolute !important; + left: 0 !important; + top: 0 !important; + padding: 5px 10px !important; } .sp-template-staff-gallery .gallery-caption strong { - display: none !important; + display: none !important; } .sp-template-gallery .sp-gallery-group-name { - margin: 0 !important; - padding: 15px !important; - background: #fff !important; - border-bottom: 1px solid #e5e5e5 !important; - font-size: 20px !important; - font-weight: 400 !important; - line-height: 1.5 !important; - display: block !important; + margin: 0 !important; + padding: 15px !important; + background: #fff !important; + border-bottom: 1px solid #e5e5e5 !important; + font-size: 20px !important; + font-weight: 400 !important; + line-height: 1.5 !important; + display: block !important; } /* Countdowns */ @@ -249,472 +249,472 @@ .sp-template-countdown .sp-event-venue, .sp-template-countdown .sp-event-league, .sp-template-countdown .sp-event-date { - margin: 0 !important; - padding: 5px 10px !important; - text-align: center !important; - line-height: 1.5 !important; - display: table !important; - width: 100% !important; - background: #fff !important; - border: 1px solid #e5e5e5 !important; - border-bottom: none !important; + margin: 0 !important; + padding: 5px 10px !important; + text-align: center !important; + line-height: 1.5 !important; + display: table !important; + width: 100% !important; + background: #fff !important; + border: 1px solid #e5e5e5 !important; + border-bottom: none !important; } .sp-template-countdown .sp-event-name { - font-size: 13px !important; - font-weight: 400 !important; - color: #333 !important; + font-size: 13px !important; + font-weight: 400 !important; + color: #333 !important; } .sp-template-countdown .sp-event-venue, .sp-template-countdown .sp-event-league, .sp-template-countdown .sp-event-date { - font-size: 12px !important; - font-weight: 500 !important; - background: #fff !important; - color: #999 !important; + font-size: 12px !important; + font-weight: 500 !important; + background: #fff !important; + color: #999 !important; } .sp-template-countdown .sp-event-venue a, .sp-template-countdown .sp-event-league a { - color: inherit !important; + color: inherit !important; } .sp-countdown time { - display: table !important; - background: #fff !important; - border: 1px solid #e5e5e5 !important; - border-collapse: collapse !important; - width: 100% !important; + display: table !important; + background: #fff !important; + border: 1px solid #e5e5e5 !important; + border-collapse: collapse !important; + width: 100% !important; } .sp-countdown span { - font-size: 20px !important; - font-weight: 400 !important; - line-height: 1.5 !important; - display: table-cell !important; - border: 1px solid #e5e5e5 !important; - padding: 10px 5px !important; - text-align: center !important; + font-size: 20px !important; + font-weight: 400 !important; + line-height: 1.5 !important; + display: table-cell !important; + border: 1px solid #e5e5e5 !important; + padding: 10px 5px !important; + text-align: center !important; } .sp-countdown span small { - font-size: 12px !important; - font-weight: 400 !important; - line-height: 1.5 !important; - font-weight: 500 !important; - color: rgba(51,51,51,0.5) !important; - display: block !important; + font-size: 12px !important; + font-weight: 400 !important; + line-height: 1.5 !important; + font-weight: 500 !important; + color: rgba(51,51,51,0.5) !important; + display: block !important; } /* Event Calendars */ .sp-template-event-calendar .sp-table-caption { - display: table-caption !important; + display: table-caption !important; } .sp-template-event-calendar td { - padding: 10px 5px !important; + padding: 10px 5px !important; } .sp-template-event-calendar tfoot td { - padding: 10px 15px !important; - border: none !important; + padding: 10px 15px !important; + border: none !important; } .sp-template-event-calendar .sp-previous-month { - text-align: left !important; + text-align: left !important; } .sp-template-event-calendar .sp-next-month { - text-align: right !important; + text-align: right !important; } .sp-template-event-calendar tfoot a { - font-size: 12px !important; - font-weight: 400 !important; - line-height: 1.5 !important; - text-decoration: none !important; - color: rgba(51,51,51,0.5) !important; + font-size: 12px !important; + font-weight: 400 !important; + line-height: 1.5 !important; + text-decoration: none !important; + color: rgba(51,51,51,0.5) !important; } .sp-template-event-calendar tfoot a:hover { - color: #333 !important; - text-decoration: none !important; + color: #333 !important; + text-decoration: none !important; } .sp-template-event-calendar tbody td { - position: relative !important; + position: relative !important; } .sp-template-event-calendar tbody td a:before { - content: '•' !important; - position: absolute !important; - font-size: 20px !important; - line-height: 1 !important; - width: 1em !important; - top: 0 !important; - right: 0 !important; + content: '•' !important; + position: absolute !important; + font-size: 20px !important; + line-height: 1 !important; + width: 1em !important; + top: 0 !important; + right: 0 !important; } /* Event Lists */ .sp-template-event-list .data-home { - text-align: right !important; + text-align: right !important; } .sp-template-event-list .data-away { - text-align: left !important; + text-align: left !important; } /* Event Blocks */ .sp-template-event-blocks td { - padding: 0 !important; + padding: 0 !important; } .sp-template-event-blocks .sp-event-date { - color: rgba(51,51,51,0.5) !important; - font-weight: 500 !important; - font-size: 12px !important; - margin: 10px !important; + color: rgba(51,51,51,0.5) !important; + font-weight: 500 !important; + font-size: 12px !important; + margin: 10px !important; } .sp-template-event-blocks .sp-event-date a, .sp-template-event-blocks .sp-event-date a:hover { - color: inherit !important; + color: inherit !important; } .sp-template-event-blocks .sp-event-results { - font-size: 20px !important; - font-weight: 400 !important; - padding: 0 !important; - margin: 0 !important; - color: #333 !important; + font-size: 20px !important; + font-weight: 400 !important; + padding: 0 !important; + margin: 0 !important; + color: #333 !important; } .sp-template-event-blocks .sp-event-results a { - color: inherit !important; + color: inherit !important; } .sp-template-event-blocks .sp-event-results a:hover { - color: inherit !important; - text-decoration: none !important; + color: inherit !important; + text-decoration: none !important; } .sp-template-event-blocks .sp-event-title, .sp-template-event-blocks .sp-event-status { - display: block !important; - padding: 0 !important; - margin: 10px !important; - font-size: 13px !important; - font-weight: 400 !important; + display: block !important; + padding: 0 !important; + margin: 10px !important; + font-size: 13px !important; + font-weight: 400 !important; } /* Event Logos */ .sp-template-event-logos .sp-team-name, .sp-template-event-logos .sp-team-result { - font-size: 20px !important; - font-weight: 400 !important; - padding: 0 !important; - margin: 0 !important; - color: #333 !important; + font-size: 20px !important; + font-weight: 400 !important; + padding: 0 !important; + margin: 0 !important; + color: #333 !important; } .sp-template-event-logos a, .sp-template-event-logos a:hover { - border: none !important; - text-decoration: none !important; + border: none !important; + text-decoration: none !important; } /* Event Performance */ .sp-template-event-performance-icons td { - border: none !important; + border: none !important; } .sp-template-event-performance-icons tr:first-child td { - border-top: 1px solid #e5e5e5 !important; + border-top: 1px solid #e5e5e5 !important; } /* Videos */ .sp-template-event-video iframe { - width: 100% !important; + width: 100% !important; } /* Match Stats */ .sp-template-event-statistics .sp-statistic-label { - font-size: 12px !important; - font-weight: 500 !important; - color: inherit !important; - opacity: 0.5 !important; + font-size: 12px !important; + font-weight: 500 !important; + color: inherit !important; + opacity: 0.5 !important; } .sp-event-statistics { - background: transparent !important; - margin: 0 0 10px !important; + background: transparent !important; + margin: 0 0 10px !important; } .sp-event-statistics, .sp-event-statistics tr, .sp-event-statistics td { - border: none !important; + border: none !important; } .sp-event-statistics .sp-statistic-ratio { - padding: 0 !important; + padding: 0 !important; } .sp-event-statistics .sp-statistic-bar { - border: 1px solid #e5e5e5 !important; - background: #f9f9f9 !important; + border: 1px solid #e5e5e5 !important; + background: #f9f9f9 !important; } /* Venues */ .sp-event-venue-map-row td { - padding: 0 !important; + padding: 0 !important; } .sp-event-venue-map-row .sp-google-map { - display: block !important; - margin: 0 !important; + display: block !important; + margin: 0 !important; } /* Teams */ .sp-template-logo { - float: right !important; - margin: 0 0 20px 20px !important; - clear: none !important; + float: right !important; + margin: 0 0 20px 20px !important; + clear: none !important; } /* Profiles */ .sp-template-details dl { - margin: 0 0 20px !important; - padding: 15px !important; - border: 1px solid #e5e5e5 !important; - background: #fff !important; + margin: 0 0 20px !important; + padding: 15px !important; + border: 1px solid #e5e5e5 !important; + background: #fff !important; } .sp-template-details dt, .sp-template-details dd { - margin: 0 !important; - padding: 0 !important; + margin: 0 !important; + padding: 0 !important; } .sp-template-details dt { - font-size: 12px !important; - font-weight: 500 !important; - color: rgba(51,51,51,0.5) !important; + font-size: 12px !important; + font-weight: 500 !important; + color: rgba(51,51,51,0.5) !important; } .sp-template-details dd { - font-size: 16px !important; - font-weight: 400 !important; - color: #333 !important; - margin-bottom: 10px !important; + font-size: 16px !important; + font-weight: 400 !important; + color: #333 !important; + margin-bottom: 10px !important; } .sp-template-details dd:last-child { - margin-bottom: 0 !important; + margin-bottom: 0 !important; } /* Twitter */ .sp-tweets { - border: 1px solid #e5e5e5 !important; - border-top: none !important; + border: 1px solid #e5e5e5 !important; + border-top: none !important; } /* Scoreboards */ .sp-header-scoreboard .sp-template-scoreboard { - margin-bottom: 0 !important; + margin-bottom: 0 !important; } .sp-template-scoreboard td { - padding: 0 !important; + padding: 0 !important; } .sp-template-scoreboard td:hover { - background: #f9f9f9 !important; + background: #f9f9f9 !important; } .sp-template-scoreboard a, .sp-template-scoreboard a:hover { - text-decoration: none !important; - color: #333 !important; + text-decoration: none !important; + color: #333 !important; } .sp-template-scoreboard .sp-scoreboard-date { - font-size: 12px !important; - font-weight: 500 !important; - color: rgba(51,51,51,0.5) !important; + font-size: 12px !important; + font-weight: 500 !important; + color: rgba(51,51,51,0.5) !important; } .sp-template-scoreboard .sp-scoreboard-nav { - color: #fff !important; - background: #00a69c !important; + color: #fff !important; + background: #00a69c !important; } /* Timelines */ .sp-template-timeline .sp-timeline * { - color: initial !important; + color: initial !important; } /* Tournaments */ .sp-tournament-bracket { - color: #333 !important; - background: transparent !important; - width: 100% !important; - border-collapse: separate !important; + color: #333 !important; + background: transparent !important; + width: 100% !important; + border-collapse: separate !important; } .sp-tournament-bracket a, .sp-tournament-bracket a:hover { - text-decoration: none !important; - color: inherit !important; - border: none! important; + text-decoration: none !important; + color: inherit !important; + border: none! important; } .sp-tournament-bracket tr, .sp-tournament-bracket th, .sp-tournament-bracket td { - border: none !important; + border: none !important; } .sp-tournament-bracket thead th { - font-size: 12px !important; - font-weight: 500 !important; - color: rgba(51,51,51,0.5) !important; - text-align: center !important; - border-bottom: 1px solid #e5e5e5 !important; + font-size: 12px !important; + font-weight: 500 !important; + color: rgba(51,51,51,0.5) !important; + text-align: center !important; + border-bottom: 1px solid #e5e5e5 !important; } .sp-tournament-bracket .sp-team-name { - font-size: 13px !important; - font-weight: 400 !important; - text-align: center !important; - background: #fff !important; - border: 1px solid #e5e5e5 !important; + font-size: 13px !important; + font-weight: 400 !important; + text-align: center !important; + background: #fff !important; + border: 1px solid #e5e5e5 !important; } .sp-tournament-bracket .sp-team-name:hover { - border: 1px solid #e5e5e5 !important; + border: 1px solid #e5e5e5 !important; } .sp-tournament-bracket .sp-heading, .sp-tournament-bracket .sp-heading:hover { - color: #fff !important; - background: #00a69c !important; - border-color: #00a69c !important; + color: #fff !important; + background: #00a69c !important; + border-color: #00a69c !important; } .sp-tournament-bracket .sp-event { - border-color: #e5e5e5 !important; - border-width: 1px !important; + border-color: #e5e5e5 !important; + border-width: 1px !important; } .sp-tournament-bracket .sp-event .sp-event-title { - font-size: 12px !important; - font-weight: 400 !important; - color: rgba(51,51,51,0.5) !important; - text-align: center !important; + font-size: 12px !important; + font-weight: 400 !important; + color: rgba(51,51,51,0.5) !important; + text-align: center !important; } .sp-tournament-bracket .sp-event .sp-event-title:hover { - color: #333 !important; + color: #333 !important; } /* Tabs */ .sp-tab-menu { - display: block !important; - clear: both !important; - margin: 0 0 20px !important; - padding: 0 !important; - list-style: none !important; + display: block !important; + clear: both !important; + margin: 0 0 20px !important; + padding: 0 !important; + list-style: none !important; } .sp-tab-menu-item { - display: inline-block !important; - margin: 0 !important; - padding: 0 !important; + display: inline-block !important; + margin: 0 !important; + padding: 0 !important; } .sp-tab-menu-item a { - margin: 0 !important; - padding: 5px 10px; - border-bottom: 2px solid transparent !important; - box-shadow: none !important; + margin: 0 !important; + padding: 5px 10px; + border-bottom: 2px solid transparent !important; + box-shadow: none !important; } .sp-tab-menu-item a:hover { - text-decoration: none !important; + text-decoration: none !important; } .sp-tab-menu-item-active a, .sp-tab-menu-item-active a:hover { - color: #00a69c !important; - border-bottom-color: #00a69c !important; + color: #00a69c !important; + border-bottom-color: #00a69c !important; } /* Messages */ .sp-template .sp-message { - color: #00a69c !important; - border-color: #00a69c !important; + color: #00a69c !important; + border-color: #00a69c !important; } /* Post Content */ .single-sp_team .has-post-thumbnail .sp-post-content { - clear: none; + clear: none; } /* Media Queries */ @media screen and (min-width: 601px) { - .sp-template-event-calendar tbody td { - padding: 15px 5px !important; - } + .sp-template-event-calendar tbody td { + padding: 15px 5px !important; + } - .sp-template-event-calendar tbody td a:before { - font-size: 25px !important; - } + .sp-template-event-calendar tbody td a:before { + font-size: 25px !important; + } - .widget .sp-template-event-calendar tbody td { - padding: 10px 5px !important; - } + .widget .sp-template-event-calendar tbody td { + padding: 10px 5px !important; + } - .widget .sp-template-event-calendar tbody td a:before { - font-size: 20px !important; - } + .widget .sp-template-event-calendar tbody td a:before { + font-size: 20px !important; + } } @media screen and (min-width: 801px) { - .sp-template-event-calendar tbody td { - padding: 20px 5px !important; - } + .sp-template-event-calendar tbody td { + padding: 20px 5px !important; + } - .sp-template-event-calendar tbody td a:before { - font-size: 30px !important; - } + .sp-template-event-calendar tbody td a:before { + font-size: 30px !important; + } - .widget .sp-template-event-calendar tbody td { - padding: 10px 5px !important; - } + .widget .sp-template-event-calendar tbody td { + padding: 10px 5px !important; + } - .widget .sp-template-event-calendar tbody td a:before { - font-size: 20px !important; - } + .widget .sp-template-event-calendar tbody td a:before { + font-size: 20px !important; + } - .sp-template-event-performance-icons.sp-template-event-performance-section:nth-child(2n) { - padding-top: 61px !important; - } -} \ No newline at end of file + .sp-template-event-performance-icons.sp-template-event-performance-section:nth-child(2n) { + padding-top: 61px !important; + } +} diff --git a/assets/css/sportspress.css b/assets/css/sportspress.css index dbd116de..7d290e45 100644 --- a/assets/css/sportspress.css +++ b/assets/css/sportspress.css @@ -61,10 +61,10 @@ margin: 0 10px; color: inherit; opacity: 0.5; - transition: all .3s; + transition: all .3s; } .sp-tab-menu-item a:focus { - outline: none; + outline: none; } .sp-tab-menu-item-active a, .sp-tab-menu-item a:hover { @@ -90,7 +90,7 @@ .sp-data-table { width: 100%; table-layout: auto; - border-spacing: 0; + border-spacing: 0; } .sp-paginated-table { margin-bottom: 0; @@ -310,12 +310,12 @@ color: #f4d014; } .sp-event-performance .sp-event-star-number { - margin-left: -20px; - width: 20px; - text-align: center; - display: inline-block; - font-size: smaller; - line-height: 20px; + margin-left: -20px; + width: 20px; + text-align: center; + display: inline-block; + font-size: smaller; + line-height: 20px; } /* Event Performance (Icons) */ @@ -335,12 +335,12 @@ } .sp-template-event-performance-icons .sp-player-position { - display: block; + display: block; } /* Event Calendar */ .sp-event-calendar { - border-spacing: 0; + border-spacing: 0; } .sp-event-calendar a { text-decoration: none; @@ -635,11 +635,11 @@ span.sp_event_spec_label { display: inline-block; margin: 0 0.25em; } - + .sp-template-logo + .sp-post-content { clear: left; } - + .sp-template-photo + .sp-post-content { clear: none; } @@ -664,15 +664,15 @@ span.sp_event_spec_label { text-align: right; float: right; } - + .sp-template-event-logos-block .logo-odd img { margin-right: 10px; } - + .sp-template-event-logos-block .logo-even img { margin-left: 10px; } - + .sp-template-event-logos-block .sp-team-name { display: inline; clear: none; diff --git a/assets/css/themes/twentyfourteen.css b/assets/css/themes/twentyfourteen.css index 3fa0c1ed..8bcc54b4 100644 --- a/assets/css/themes/twentyfourteen.css +++ b/assets/css/themes/twentyfourteen.css @@ -6,4 +6,4 @@ .sportspress-page .entry-content h4:first-child { margin-top: 36px; -} \ No newline at end of file +} diff --git a/assets/js/admin/colorpicker.js b/assets/js/admin/colorpicker.js index 95aaa618..7d400fb0 100644 --- a/assets/js/admin/colorpicker.js +++ b/assets/js/admin/colorpicker.js @@ -1,26 +1,38 @@ -jQuery(document).ready(function($){ +jQuery( document ).ready( + function($){ - // Color picker - $('.colorpick').iris( { - change: function(event, ui){ - $(this).css( { backgroundColor: ui.color.toString() } ); - }, - hide: true, - border: true - } ).each( function() { - $(this).css( { backgroundColor: $(this).val() } ); - }) - .click(function(){ - $('.iris-picker').hide(); - $(this).closest('.sp-color-box, td').find('.iris-picker').show(); - }); + // Color picker + $( '.colorpick' ).iris( + { + change: function(event, ui){ + $( this ).css( { backgroundColor: ui.color.toString() } ); + }, + hide: true, + border: true + } + ).each( + function() { + $( this ).css( { backgroundColor: $( this ).val() } ); + } + ) + .click( + function(){ + $( '.iris-picker' ).hide(); + $( this ).closest( '.sp-color-box, td' ).find( '.iris-picker' ).show(); + } + ); - $('body').click(function() { - $('.iris-picker').hide(); - }); + $( 'body' ).click( + function() { + $( '.iris-picker' ).hide(); + } + ); - $('.sp-color-box, .colorpick').click(function(event){ - event.stopPropagation(); - }); + $( '.sp-color-box, .colorpick' ).click( + function(event){ + event.stopPropagation(); + } + ); -}); \ No newline at end of file + } +); diff --git a/assets/js/admin/dashboard.js b/assets/js/admin/dashboard.js index 7ab9f30c..a07e792a 100644 --- a/assets/js/admin/dashboard.js +++ b/assets/js/admin/dashboard.js @@ -1,11 +1,18 @@ -jQuery(document).ready(function($){ +jQuery( document ).ready( + function($){ - // Dashboard countdown - $("#sportspress_dashboard_status .sp_status_list li.countdown").each(function() { - var $this = $(this), finalDate = $(this).data('countdown'); - $this.countdown(finalDate, function(event) { - $this.find('strong').html(event.strftime("%D "+localized_strings.days+" %H:%M:%S")); - }); - }); + // Dashboard countdown + $( "#sportspress_dashboard_status .sp_status_list li.countdown" ).each( + function() { + var $this = $( this ), finalDate = $( this ).data( 'countdown' ); + $this.countdown( + finalDate, + function(event) { + $this.find( 'strong' ).html( event.strftime( "%D " + localized_strings.days + " %H:%M:%S" ) ); + } + ); + } + ); -}); \ No newline at end of file + } +); diff --git a/assets/js/admin/editor-lang.php b/assets/js/admin/editor-lang.php index 0e0e00ca..15ba4487 100644 --- a/assets/js/admin/editor-lang.php +++ b/assets/js/admin/editor-lang.php @@ -3,51 +3,63 @@ $shortcodes = ''; $options = array( - 'event' => array( - 'details', 'results', 'performance', 'venue', 'officials', 'teams', 'full', - ), - 'team' => array(), - 'player' => array( - 'details', 'statistics' - ), + 'event' => array( + 'details', + 'results', + 'performance', + 'venue', + 'officials', + 'teams', + 'full', + ), + 'team' => array(), + 'player' => array( + 'details', + 'statistics', + ), ); $options = apply_filters( 'sportspress_shortcodes', $options ); foreach ( $options as $name => $group ) { - if ( empty( $group ) ) continue; - $shortcodes .= $name . '[' . implode( '|', $group ) . ']'; + if ( empty( $group ) ) { + continue; + } + $shortcodes .= $name . '[' . implode( '|', $group ) . ']'; } -$raw = apply_filters( 'sportspress_tinymce_strings', array( - 'shortcodes' => $shortcodes, - 'insert' => __( 'SportsPress Shortcodes', 'sportspress' ), - 'auto' => __( 'Auto', 'sportspress' ), - 'manual' => __( 'Manual', 'sportspress' ), - 'select' => __( 'Select...', 'sportspress' ), - 'event' => __( 'Event', 'sportspress' ), - 'details' => __( 'Details', 'sportspress' ), - 'results' => __( 'Results', 'sportspress' ), - 'countdown' => __( 'Countdown', 'sportspress' ), - 'performance' => __( 'Box Score', 'sportspress' ), - 'venue' => __( 'Venue', 'sportspress' ), - 'officials' => __( 'Officials', 'sportspress' ), - 'teams' => __( 'Teams', 'sportspress' ), - 'full' => __( 'Full Info', 'sportspress' ), - 'calendar' => __( 'Calendar', 'sportspress' ), - 'statistics' => __( 'Statistics', 'sportspress' ), - 'team' => __( 'Team', 'sportspress' ), - 'standings' => __( 'League Table', 'sportspress' ), - 'player' => __( 'Player', 'sportspress' ), - 'list' => __( 'List', 'sportspress' ), - 'blocks' => __( 'Blocks', 'sportspress' ), - 'gallery' => __( 'Gallery', 'sportspress' ), -)); +$raw = apply_filters( + 'sportspress_tinymce_strings', + array( + 'shortcodes' => $shortcodes, + 'insert' => __( 'SportsPress Shortcodes', 'sportspress' ), + 'auto' => __( 'Auto', 'sportspress' ), + 'manual' => __( 'Manual', 'sportspress' ), + 'select' => __( 'Select...', 'sportspress' ), + 'event' => __( 'Event', 'sportspress' ), + 'details' => __( 'Details', 'sportspress' ), + 'results' => __( 'Results', 'sportspress' ), + 'countdown' => __( 'Countdown', 'sportspress' ), + 'performance' => __( 'Box Score', 'sportspress' ), + 'venue' => __( 'Venue', 'sportspress' ), + 'officials' => __( 'Officials', 'sportspress' ), + 'teams' => __( 'Teams', 'sportspress' ), + 'full' => __( 'Full Info', 'sportspress' ), + 'calendar' => __( 'Calendar', 'sportspress' ), + 'statistics' => __( 'Statistics', 'sportspress' ), + 'team' => __( 'Team', 'sportspress' ), + 'standings' => __( 'League Table', 'sportspress' ), + 'player' => __( 'Player', 'sportspress' ), + 'list' => __( 'List', 'sportspress' ), + 'blocks' => __( 'Blocks', 'sportspress' ), + 'gallery' => __( 'Gallery', 'sportspress' ), + ) +); $formatted = array(); foreach ( $raw as $key => $value ) { - $formatted[] = $key . ': "' . esc_js( $value ) . '"'; + $formatted[] = $key . ': "' . esc_js( $value ) . '"'; } $strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{ diff --git a/assets/js/admin/editor.js b/assets/js/admin/editor.js index 74555b83..ebd7cd44 100644 --- a/assets/js/admin/editor.js +++ b/assets/js/admin/editor.js @@ -1,42 +1,58 @@ /* global tinymce */ ( function () { - tinymce.PluginManager.add( 'sp_shortcodes_button', function( editor, url ) { - var ed = tinymce.activeEditor; + tinymce.PluginManager.add( + 'sp_shortcodes_button', + function( editor, url ) { + var ed = tinymce.activeEditor; - var groups = ed.getLang( 'sportspress.shortcodes' ).split("]"); - var menu = new Array(); + var groups = ed.getLang( 'sportspress.shortcodes' ).split( "]" ); + var menu = new Array(); - groups.forEach(function(g) { - if ( "" == g ) return; - var p = g.split("["); - var label = p.shift(); - var variations = p.shift(); - var shortcodes = typeof variations!== 'undefined' ? variations.split("|") : []; - var submenu = new Array(); - shortcodes.forEach(function(s) { - submenu.push({ - text: ed.getLang( 'sportspress.' + s ), - onclick: function() { - // triggers the thickbox - var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; - W = W - 80; - H = H - 84; - tb_show( ed.getLang( 'sportspress.' + label ) + ' - ' + ed.getLang( 'sportspress.' + s ), 'admin-ajax.php?action=sportspress_' + label + '_' + s + '_shortcode&width=' + W + '&height=' + H ); + groups.forEach( + function(g) { + if ( "" == g ) { + return; } - }); - }); - menu.push({ - text: ed.getLang( 'sportspress.' + label ), - menu: submenu - }); - }); + var p = g.split( "[" ); + var label = p.shift(); + var variations = p.shift(); + var shortcodes = typeof variations !== 'undefined' ? variations.split( "|" ) : []; + var submenu = new Array(); + shortcodes.forEach( + function(s) { + submenu.push( + { + text: ed.getLang( 'sportspress.' + s ), + onclick: function() { + // triggers the thickbox + var width = jQuery( window ).width(), H = jQuery( window ).height(), W = ( 720 < width ) ? 720 : width; + W = W - 80; + H = H - 84; + tb_show( ed.getLang( 'sportspress.' + label ) + ' - ' + ed.getLang( 'sportspress.' + s ), 'admin-ajax.php?action=sportspress_' + label + '_' + s + '_shortcode&width=' + W + '&height=' + H ); + } + } + ); + } + ); + menu.push( + { + text: ed.getLang( 'sportspress.' + label ), + menu: submenu + } + ); + } + ); - editor.addButton( 'sp_shortcodes_button', { - title: ed.getLang('sportspress.insert'), - text: false, - icon: false, - type: 'menubutton', - menu: menu - }); - }); + editor.addButton( + 'sp_shortcodes_button', + { + title: ed.getLang( 'sportspress.insert' ), + text: false, + icon: false, + type: 'menubutton', + menu: menu + } + ); + } + ); })(); diff --git a/assets/js/admin/equationbuilder.js b/assets/js/admin/equationbuilder.js index be5e248c..805f1711 100644 --- a/assets/js/admin/equationbuilder.js +++ b/assets/js/admin/equationbuilder.js @@ -1,37 +1,55 @@ -jQuery(document).ready(function($){ - $("#title").keyup(function() { - val = $(this).val(); - if ( val == '' ) val = 'f(x)'; - $(".sp-equation-variable").text( val + ' =' ); - }); +jQuery( document ).ready( + function($){ + $( "#title" ).keyup( + function() { + val = $( this ).val(); + if ( val == '' ) { + val = 'f(x)'; + } + $( ".sp-equation-variable" ).text( val + ' =' ); + } + ); - $(".sp-equation-parts .button").draggable({ - appendTo: "body", - helper: "clone", - cursor: "move", - distance: 10, - containment: "#sp_equationdiv", - }).click(function() { - $("").text( $(this).text() ).append("×").appendTo( $(".sp-equation-formula") ); - }); + $( ".sp-equation-parts .button" ).draggable( + { + appendTo: "body", + helper: "clone", + cursor: "move", + distance: 10, + containment: "#sp_equationdiv", + } + ).click( + function() { + $( "" ).text( $( this ).text() ).append( "×" ).appendTo( $( ".sp-equation-formula" ) ); + } + ); - $(".sp-equation").droppable({ - activeClass: "ui-state-active", - hoverClass: "ui-state-hover", - accept: ".button:not(.ui-sortable-helper)", - drop: function( event, ui ) { - $("").text( ui.draggable.text() ).append("×").appendTo( $(".sp-equation-formula") ); - } - }).sortable({ - items: ".button", - tolerance: "pointer", - containment: "#sp_equationdiv", - sort: function() { - $( this ).removeClass( "ui-state-active" ); - } - }); + $( ".sp-equation" ).droppable( + { + activeClass: "ui-state-active", + hoverClass: "ui-state-hover", + accept: ".button:not(.ui-sortable-helper)", + drop: function( event, ui ) { + $( "" ).text( ui.draggable.text() ).append( "×" ).appendTo( $( ".sp-equation-formula" ) ); + } + } + ).sortable( + { + items: ".button", + tolerance: "pointer", + containment: "#sp_equationdiv", + sort: function() { + $( this ).removeClass( "ui-state-active" ); + } + } + ); - $(".sp-equation-formula").on("click", ".button .remove", function() { - $(this).closest(".button").remove(); - }); -}); \ No newline at end of file + $( ".sp-equation-formula" ).on( + "click", + ".button .remove", + function() { + $( this ).closest( ".button" ).remove(); + } + ); + } +); diff --git a/assets/js/admin/iconpicker.js b/assets/js/admin/iconpicker.js index 565e9dc1..e0816af9 100644 --- a/assets/js/admin/iconpicker.js +++ b/assets/js/admin/iconpicker.js @@ -1,37 +1,52 @@ -jQuery(document).ready(function($){ +jQuery( document ).ready( + function($){ - // Icon picker - $('.sp-icons input').on('change', function() { - if ('' == $(this).val()) { - $('.sp-custom-colors').hide(); - $('.sp-custom-thumbnail').show(); - } else { - $('.sp-custom-thumbnail').hide(); - $('.sp-custom-colors').show(); - } - }); + // Icon picker + $( '.sp-icons input' ).on( + 'change', + function() { + if ('' == $( this ).val()) { + $( '.sp-custom-colors' ).hide(); + $( '.sp-custom-thumbnail' ).show(); + } else { + $( '.sp-custom-thumbnail' ).hide(); + $( '.sp-custom-colors' ).show(); + } + } + ); - // Color picker - $('.colorpick').iris( { - change: function(event, ui){ - $(this).css( { backgroundColor: ui.color.toString() } ); - }, - hide: true, - border: true - } ).each( function() { - $(this).css( { backgroundColor: $(this).val() } ); - }) - .click(function(){ - $('.iris-picker').hide(); - $(this).closest('.sp-color-box-for-icon, td').find('.iris-picker').show(); - }); + // Color picker + $( '.colorpick' ).iris( + { + change: function(event, ui){ + $( this ).css( { backgroundColor: ui.color.toString() } ); + }, + hide: true, + border: true + } + ).each( + function() { + $( this ).css( { backgroundColor: $( this ).val() } ); + } + ) + .click( + function(){ + $( '.iris-picker' ).hide(); + $( this ).closest( '.sp-color-box-for-icon, td' ).find( '.iris-picker' ).show(); + } + ); - $('body').click(function() { - $('.iris-picker').hide(); - }); + $( 'body' ).click( + function() { + $( '.iris-picker' ).hide(); + } + ); - $('.sp-color-box-for-icon, .colorpick').click(function(event){ - event.stopPropagation(); - }); + $( '.sp-color-box-for-icon, .colorpick' ).click( + function(event){ + event.stopPropagation(); + } + ); -}); \ No newline at end of file + } +); diff --git a/assets/js/admin/quickeditor.js b/assets/js/admin/quickeditor.js index f5979e22..762d4b0c 100644 --- a/assets/js/admin/quickeditor.js +++ b/assets/js/admin/quickeditor.js @@ -24,56 +24,72 @@ var $post_row = $( '#post-' + $post_id ); // get the data - var $number = $( '.column-sp_number', $post_row ).text(); - var $current_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'current-teams' ) ).split(','); - var $past_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'past-teams' ) ).split(','); + var $number = $( '.column-sp_number', $post_row ).text(); + var $current_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'current-teams' ) ).split( ',' ); + var $past_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'past-teams' ) ).split( ',' ); // populate the data $( ':input[name="sp_number"]', $edit_row ).val( $number ); - $( ':input[name="sp_current_team[]"]', $edit_row ).each(function() { - $(this).prop("checked", ($.inArray($(this).val(), $current_teams ) != -1)); - }); - $( ':input[name="sp_past_team[]"]', $edit_row ).each(function() { - $(this).prop("checked", ($.inArray($(this).val(), $past_teams ) != -1)); - }); + $( ':input[name="sp_current_team[]"]', $edit_row ).each( + function() { + $( this ).prop( "checked", ($.inArray( $( this ).val(), $current_teams ) != -1) ); + } + ); + $( ':input[name="sp_past_team[]"]', $edit_row ).each( + function() { + $( this ).prop( "checked", ($.inArray( $( this ).val(), $past_teams ) != -1) ); + } + ); } }; - $( document ).on( 'click', '#bulk_edit', function() { - // define the bulk edit row - var $bulk_row = $( '#bulk-edit' ); + $( document ).on( + 'click', + '#bulk_edit', + function() { + // define the bulk edit row + var $bulk_row = $( '#bulk-edit' ); - // get the selected post ids that are being edited - var $post_ids = new Array(); - $bulk_row.find( '#bulk-titles' ).children().each( function() { - $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) ); - }); + // get the selected post ids that are being edited + var $post_ids = new Array(); + $bulk_row.find( '#bulk-titles' ).children().each( + function() { + $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) ); + } + ); - // get the data - var $current_teams = []; - $bulk_row.find( 'input[name="sp_current_team[]"]:checked' ).each(function() { - $current_teams.push( $(this).val() ); - }); + // get the data + var $current_teams = []; + $bulk_row.find( 'input[name="sp_current_team[]"]:checked' ).each( + function() { + $current_teams.push( $( this ).val() ); + } + ); - var $past_teams = []; - $bulk_row.find( 'input[name="sp_past_team[]"]:checked' ).each(function() { - $past_teams.push( $(this).val() ); - }); + var $past_teams = []; + $bulk_row.find( 'input[name="sp_past_team[]"]:checked' ).each( + function() { + $past_teams.push( $( this ).val() ); + } + ); - // save the data - $.ajax({ - url: ajaxurl, // this is a variable that WordPress has already defined for us - type: 'POST', - async: false, - cache: false, - data: { - action: 'save_bulk_edit_sp_player', - post_ids: $post_ids, - current_teams: $current_teams, - past_teams: $past_teams, - nonce: $("#sp_player_edit_nonce").val() - } - }); - }); + // save the data + $.ajax( + { + url: ajaxurl, // this is a variable that WordPress has already defined for us + type: 'POST', + async: false, + cache: false, + data: { + action: 'save_bulk_edit_sp_player', + post_ids: $post_ids, + current_teams: $current_teams, + past_teams: $past_teams, + nonce: $( "#sp_player_edit_nonce" ).val() + } + } + ); + } + ); -})(jQuery); \ No newline at end of file +})( jQuery ); diff --git a/assets/js/admin/settings.js b/assets/js/admin/settings.js index 0a1d67d4..3e5638a1 100644 --- a/assets/js/admin/settings.js +++ b/assets/js/admin/settings.js @@ -1,64 +1,92 @@ -jQuery(document).ready(function($){ +jQuery( document ).ready( + function($){ - // Display custom sport name field as needed - $("body.toplevel_page_sportspress #sportspress_sport").change(function() { - $target = $("#sportspress_custom_sport_name"); - if ( $(this).val() == "custom" ) - $target.show(); - else - $target.hide(); - }); + // Display custom sport name field as needed + $( "body.toplevel_page_sportspress #sportspress_sport" ).change( + function() { + $target = $( "#sportspress_custom_sport_name" ); + if ( $( this ).val() == "custom" ) { + $target.show(); + } else { + $target.hide(); + } + } + ); - // Color picker - $('.colorpick').iris( { - change: function(event, ui){ - $(this).css( { backgroundColor: ui.color.toString() } ); - }, - hide: true, - border: true - } ).each( function() { - $(this).css( { backgroundColor: $(this).val() } ); - }) - .click(function(){ - $('.iris-picker').hide(); - $(this).closest('.sp-color-box, td').find('.iris-picker').show(); - }); + // Color picker + $( '.colorpick' ).iris( + { + change: function(event, ui){ + $( this ).css( { backgroundColor: ui.color.toString() } ); + }, + hide: true, + border: true + } + ).each( + function() { + $( this ).css( { backgroundColor: $( this ).val() } ); + } + ) + .click( + function(){ + $( '.iris-picker' ).hide(); + $( this ).closest( '.sp-color-box, td' ).find( '.iris-picker' ).show(); + } + ); - $('body').click(function() { - $('.iris-picker').hide(); - }); + $( 'body' ).click( + function() { + $( '.iris-picker' ).hide(); + } + ); - $('.sp-color-box, .colorpick').click(function(event){ - event.stopPropagation(); - }); + $( '.sp-color-box, .colorpick' ).click( + function(event){ + event.stopPropagation(); + } + ); - // Chosen select - $(".chosen-select").chosen({ - allow_single_deselect: true, - single_backstroke_delete: false, - placeholder_text_multiple: localized_strings.none - }); + // Chosen select + $( ".chosen-select" ).chosen( + { + allow_single_deselect: true, + single_backstroke_delete: false, + placeholder_text_multiple: localized_strings.none + } + ); - // Preset field modifier - $(".sp-custom-input-wrapper .preset").click(function() { - val = $(this).val(); - if(val == "\\c\\u\\s\\t\\o\\m") return true; - example = $(this).attr("data-example"); - $(this).closest(".sp-custom-input-wrapper").find(".value").val(val).siblings(".example").html(example); - }); + // Preset field modifier + $( ".sp-custom-input-wrapper .preset" ).click( + function() { + val = $( this ).val(); + if (val == "\\c\\u\\s\\t\\o\\m") { + return true; + } + example = $( this ).attr( "data-example" ); + $( this ).closest( ".sp-custom-input-wrapper" ).find( ".value" ).val( val ).siblings( ".example" ).html( example ); + } + ); - // Select custom preset when field is brought to focus - $(".sp-custom-input-wrapper .value").focus(function() { - $(this).siblings("label").find(".preset").prop("checked", true); - }); + // Select custom preset when field is brought to focus + $( ".sp-custom-input-wrapper .value" ).focus( + function() { + $( this ).siblings( "label" ).find( ".preset" ).prop( "checked", true ); + } + ); - // Adjust example field when custom preset is entered - $(".sp-custom-input-wrapper .value").on("keyup", function() { - val = $(this).val(); - if ( val === undefined ) return true; - format = $(this).attr("data-example-format"); - example = format.replace(/__val__/g, val); - $(this).siblings(".example").html(example); - }); + // Adjust example field when custom preset is entered + $( ".sp-custom-input-wrapper .value" ).on( + "keyup", + function() { + val = $( this ).val(); + if ( val === undefined ) { + return true; + } + format = $( this ).attr( "data-example-format" ); + example = format.replace( /__val__/g, val ); + $( this ).siblings( ".example" ).html( example ); + } + ); -}); \ No newline at end of file + } +); diff --git a/assets/js/admin/sp-geocoder.js b/assets/js/admin/sp-geocoder.js index 00ce4039..1cb26357 100644 --- a/assets/js/admin/sp-geocoder.js +++ b/assets/js/admin/sp-geocoder.js @@ -1,54 +1,76 @@ -//Get variables form input values -latitude = document.getElementById('term_meta[sp_latitude]').value; -longitude = document.getElementById('term_meta[sp_longitude]').value; - -//Initialize the map and add the Search control box -var map = L.map('sp-location-picker').setView([latitude, longitude], 15), +// Get variables form input values +latitude = document.getElementById( 'term_meta[sp_latitude]' ).value; +longitude = document.getElementById( 'term_meta[sp_longitude]' ).value; + +// Initialize the map and add the Search control box +var map = L.map( 'sp-location-picker' ).setView( [latitude, longitude], 15 ), geocoder = L.Control.Geocoder.nominatim(), - control = L.Control.geocoder({ - geocoder: geocoder, - collapsed: false, - defaultMarkGeocode: false - }).addTo(map), - //Add a marker to use from the begining - marker = L.marker([latitude, longitude],{draggable: true, autoPan: true}).addTo(map); - -L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { - attribution: '© OpenStreetMap contributors' -}).addTo(map); - -//Pass the values to the fields after dragging -marker.on('dragend', function (e) { - document.getElementById('term_meta[sp_latitude]').value = marker.getLatLng().lat; - document.getElementById('term_meta[sp_longitude]').value = marker.getLatLng().lng; - geocoder.reverse(marker.getLatLng(), map.options.crs.scale(map.getZoom()), function(results) { - var r = results[0]; - if (r) { - document.getElementById('term_meta[sp_address]').value = r.name; + control = L.Control.geocoder( + { + geocoder: geocoder, + collapsed: false, + defaultMarkGeocode: false } - }) -}); + ).addTo( map ), + // Add a marker to use from the begining + marker = L.marker( [latitude, longitude],{draggable: true, autoPan: true} ).addTo( map ); -//After searching -control.on('markgeocode', function(e) { - var center = e.geocode.center; - var address = e.geocode.name; - map.setView([center.lat, center.lng], 15); //Center map to the new place - map.removeLayer(marker); //Remove previous marker - marker = L.marker([center.lat, center.lng],{draggable: true, autoPan: true}).addTo(map); //Add new marker to use - //Pass the values to the fields after searching - document.getElementById('term_meta[sp_latitude]').value = center.lat; - document.getElementById('term_meta[sp_longitude]').value = center.lng; - document.getElementById('term_meta[sp_address]').value = address; - //Pass the values to the fields after dragging - marker.on('dragend', function (e) { - document.getElementById('term_meta[sp_latitude]').value = marker.getLatLng().lat; - document.getElementById('term_meta[sp_longitude]').value = marker.getLatLng().lng; - geocoder.reverse(marker.getLatLng(), map.options.crs.scale(map.getZoom()), function(results) { - var r = results[0]; - if (r) { - document.getElementById('term_meta[sp_address]').value = r.name; +L.tileLayer( + 'http://{s}.tile.osm.org/{z}/{x}/{y}.png', + { + attribution: '© OpenStreetMap contributors' + } +).addTo( map ); + +// Pass the values to the fields after dragging +marker.on( + 'dragend', + function (e) { + document.getElementById( 'term_meta[sp_latitude]' ).value = marker.getLatLng().lat; + document.getElementById( 'term_meta[sp_longitude]' ).value = marker.getLatLng().lng; + geocoder.reverse( + marker.getLatLng(), + map.options.crs.scale( map.getZoom() ), + function(results) { + var r = results[0]; + if (r) { + document.getElementById( 'term_meta[sp_address]' ).value = r.name; + } } - }) - }); -}).addTo(map); \ No newline at end of file + ) + } +); + +// After searching +control.on( + 'markgeocode', + function(e) { + var center = e.geocode.center; + var address = e.geocode.name; + map.setView( [center.lat, center.lng], 15 ); // Center map to the new place + map.removeLayer( marker ); // Remove previous marker + marker = L.marker( [center.lat, center.lng],{draggable: true, autoPan: true} ).addTo( map ); // Add new marker to use + // Pass the values to the fields after searching + document.getElementById( 'term_meta[sp_latitude]' ).value = center.lat; + document.getElementById( 'term_meta[sp_longitude]' ).value = center.lng; + document.getElementById( 'term_meta[sp_address]' ).value = address; + // Pass the values to the fields after dragging + marker.on( + 'dragend', + function (e) { + document.getElementById( 'term_meta[sp_latitude]' ).value = marker.getLatLng().lat; + document.getElementById( 'term_meta[sp_longitude]' ).value = marker.getLatLng().lng; + geocoder.reverse( + marker.getLatLng(), + map.options.crs.scale( map.getZoom() ), + function(results) { + var r = results[0]; + if (r) { + document.getElementById( 'term_meta[sp_address]' ).value = r.name; + } + } + ) + } + ); + } +).addTo( map ); diff --git a/assets/js/admin/sp-setup-geocoder.js b/assets/js/admin/sp-setup-geocoder.js index 504b6329..6ee63b04 100644 --- a/assets/js/admin/sp-setup-geocoder.js +++ b/assets/js/admin/sp-setup-geocoder.js @@ -1,54 +1,76 @@ -//Get variables form input values -latitude = document.getElementById('sp_latitude').value; -longitude = document.getElementById('sp_longitude').value; - -//Initialize the map and add the Search control box -var map = L.map('sp-location-picker').setView([latitude, longitude], 15), +// Get variables form input values +latitude = document.getElementById( 'sp_latitude' ).value; +longitude = document.getElementById( 'sp_longitude' ).value; + +// Initialize the map and add the Search control box +var map = L.map( 'sp-location-picker' ).setView( [latitude, longitude], 15 ), geocoder = L.Control.Geocoder.nominatim(), - control = L.Control.geocoder({ - geocoder: geocoder, - collapsed: false, - defaultMarkGeocode: false - }).addTo(map), - //Add a marker to use from the begining - marker = L.marker([latitude, longitude],{draggable: true, autoPan: true}).addTo(map); - -L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { - attribution: '© OpenStreetMap contributors' -}).addTo(map); - -//Pass the values to the fields after dragging -marker.on('dragend', function (e) { - document.getElementById('sp_latitude').value = marker.getLatLng().lat; - document.getElementById('sp_longitude').value = marker.getLatLng().lng; - geocoder.reverse(marker.getLatLng(), map.options.crs.scale(map.getZoom()), function(results) { - var r = results[0]; - if (r) { - document.getElementById('sp_address').value = r.name; + control = L.Control.geocoder( + { + geocoder: geocoder, + collapsed: false, + defaultMarkGeocode: false } - }) -}); + ).addTo( map ), + // Add a marker to use from the begining + marker = L.marker( [latitude, longitude],{draggable: true, autoPan: true} ).addTo( map ); -//After searching -control.on('markgeocode', function(e) { - var center = e.geocode.center; - var address = e.geocode.name; - map.setView([center.lat, center.lng], 15); //Center map to the new place - map.removeLayer(marker); //Remove previous marker - marker = L.marker([center.lat, center.lng],{draggable: true, autoPan: true}).addTo(map); //Add new marker to use - //Pass the values to the fields after searching - document.getElementById('sp_latitude').value = center.lat; - document.getElementById('sp_longitude').value = center.lng; - document.getElementById('sp_address').value = address; - //Pass the values to the fields after dragging - marker.on('dragend', function (e) { - document.getElementById('sp_latitude').value = marker.getLatLng().lat; - document.getElementById('sp_longitude').value = marker.getLatLng().lng; - geocoder.reverse(marker.getLatLng(), map.options.crs.scale(map.getZoom()), function(results) { - var r = results[0]; - if (r) { - document.getElementById('sp_address').value = r.name; +L.tileLayer( + 'http://{s}.tile.osm.org/{z}/{x}/{y}.png', + { + attribution: '© OpenStreetMap contributors' + } +).addTo( map ); + +// Pass the values to the fields after dragging +marker.on( + 'dragend', + function (e) { + document.getElementById( 'sp_latitude' ).value = marker.getLatLng().lat; + document.getElementById( 'sp_longitude' ).value = marker.getLatLng().lng; + geocoder.reverse( + marker.getLatLng(), + map.options.crs.scale( map.getZoom() ), + function(results) { + var r = results[0]; + if (r) { + document.getElementById( 'sp_address' ).value = r.name; + } } - }) - }); -}).addTo(map); \ No newline at end of file + ) + } +); + +// After searching +control.on( + 'markgeocode', + function(e) { + var center = e.geocode.center; + var address = e.geocode.name; + map.setView( [center.lat, center.lng], 15 ); // Center map to the new place + map.removeLayer( marker ); // Remove previous marker + marker = L.marker( [center.lat, center.lng],{draggable: true, autoPan: true} ).addTo( map ); // Add new marker to use + // Pass the values to the fields after searching + document.getElementById( 'sp_latitude' ).value = center.lat; + document.getElementById( 'sp_longitude' ).value = center.lng; + document.getElementById( 'sp_address' ).value = address; + // Pass the values to the fields after dragging + marker.on( + 'dragend', + function (e) { + document.getElementById( 'sp_latitude' ).value = marker.getLatLng().lat; + document.getElementById( 'sp_longitude' ).value = marker.getLatLng().lng; + geocoder.reverse( + marker.getLatLng(), + map.options.crs.scale( map.getZoom() ), + function(results) { + var r = results[0]; + if (r) { + document.getElementById( 'sp_address' ).value = r.name; + } + } + ) + } + ); + } +).addTo( map ); diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index 10c3f502..ae575fc2 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -1,901 +1,1187 @@ -jQuery(document).ready(function($){ +jQuery( document ).ready( + function($){ - // Tiptip - $(".sp-tip").tipTip({ - delay: 200, - fadeIn: 100, - fadeOut: 100 - }); - $(".sp-desc-tip").tipTip({ - delay: 200, - fadeIn: 100, - fadeOut: 100, - defaultPosition: 'right' - }); - - // Chosen select - $(document).on("postbox-toggled", function() { - $(".chosen-select").filter(":visible").chosen({ - allow_single_deselect: true, - search_contains: true, - single_backstroke_delete: false, - disable_search_threshold: 10, - placeholder_text_multiple: localized_strings.none - }); - }).trigger("postbox-toggled"); - - - // Auto key placeholder - $("#poststuff #title").on("keyup", function() { - val = $(this).val() - lc = val.replace(/[^a-z]/gi,"").toLowerCase(); - $("#sp_key").attr("placeholder", lc); - $("#sp_default_key").val(lc); - $("#sp_singular").attr("placeholder", val); - }); - - // Activate auto key placeholder - $("#poststuff #title").keyup(); - - // Radio input toggle - $(".sp-radio-toggle").click(function() { - if($(this).data("sp-checked")) { - $(this).prop("checked", false ); - $(this).data("sp-checked", false ); - } else { - $(this).data("sp-checked", true ); - } - }); - - // Table switcher - $(".sp-table-panel").siblings(".sp-table-bar").find("a").click(function() { - $(this).closest("li").find("a").addClass("current").closest("li").siblings().find("a").removeClass("current").closest(".sp-table-bar").siblings($(this).attr("href")).show().siblings(".sp-table-panel").hide(); - return false; - }); - - // Tab switcher - $(".sp-tab-panel").siblings(".sp-tab-bar").find("a").click(function() { - $(this).closest("li").addClass("tabs").siblings().removeClass("tabs").closest(".sp-tab-bar").siblings($(this).attr("href")).show().trigger('checkCheck').siblings(".sp-tab-panel").hide(); - return false; - }); - - // Tab filter - $(".sp-tab-filter-panel").siblings(".sp-tab-select").find("select").change(function() { - var val = $(this).val(); - var filter = ".sp-filter-"+val; - var $filters = $(this).closest(".sp-tab-select").siblings(".sp-tab-select"); - if($filters.length) { - $filters.each(function() { - filterval = $(this).find("select").val(); - if(filterval !== undefined) - filter += ".sp-filter-"+filterval; - }); - } - $panel = $(this).closest(".sp-tab-select").siblings(".sp-tab-panel"); - $panel.each(function() { - $(this).find(".sp-post").hide(0, function() { - $(this).find("input").prop("disabled", true); - $(this).filter(filter).show(0, function() { - $(this).find("input").prop("disabled", false); - }); - }); - if($(this).find(".sp-post:visible").length > 0) { - $(this).find(".sp-select-all-container").show(); - $(this).find(".sp-show-all-container").show(); - $(this).find(".sp-not-found-container").hide(); - } else { - $(this).find(".sp-select-all-container").hide(); - $(this).find(".sp-show-all-container").hide(); - $(this).find(".sp-not-found-container").show(); + // Tiptip + $( ".sp-tip" ).tipTip( + { + delay: 200, + fadeIn: 100, + fadeOut: 100 } - }); - }); - - // Trigger tab filter - $(".sp-tab-filter-panel").siblings(".sp-tab-select").find("select").change(); - - // Dropdown filter - $(".sp-dropdown-target").siblings(".sp-dropdown-filter").find("select").change(function() { - var val = $(this).val(); - var filter = ".sp-filter-"+val; - var $filters = $(this).closest(".sp-dropdown-filter").siblings(".sp-dropdown-filter"); - if($filters.length) { - $filters.each(function() { - filterval = $(this).find("select").val(); - if(filterval !== undefined) - filter += ".sp-filter-"+filterval; - }); - } - $target = $(this).closest(".sp-dropdown-filter").siblings(".sp-dropdown-target").find("select"); - $target.find(".sp-post").prop("disabled", true).each(function() { - $(this).filter(filter).prop("disabled", false); - }); - }); - - // Trigger dropdown filter - $(".sp-dropdown-target").siblings(".sp-dropdown-filter").find("select").change(); - - // Filter show all action links - $(".sp-tab-panel").find(".sp-post input:checked").each(function() { - $(this).prop("disabled", false).closest("li").show().siblings(".sp-not-found-container").hide().siblings(".sp-show-all-container").show(); - }); - - // Show all filter - $(".sp-tab-panel").on("click", ".sp-show-all", function() { - $(this).closest("li").hide().siblings(".sp-post, .sp-select-all-container").show().find("input").prop("disabled", false); - }); - - // Self-cloning - $(".sp-clone:last").find("select").change(function() { - $(this).closest(".sp-clone").siblings().find("select").change(function() { - if($(this).val() == "0") $(this).closest(".sp-clone").remove(); - }).find("option:first").text(localized_strings.remove_text); - if($(this).val() != "0") { - $original = $(this).closest(".sp-clone"); - $original.before($original.clone().find("select").attr("name", $original.attr("data-clone-name") + "[]").val($(this).val()).closest(".sp-clone")).attr("data-clone-num", parseInt($original.attr("data-clone-num")) + 1).find("select").val("0").change(); - } - }); - - // Activate self-cloning - $(".sp-clone:last").find("select").change(); - - // Custom value editor - $(".sp-data-table .sp-default-value").click(function() { - $(this).hide().siblings(".sp-custom-value").show().find(".sp-custom-value-input").focus(); - }); - - // Define custom value editor saving - $(".sp-data-table .sp-custom-value .sp-custom-value-input").on("saveInput", function() { - $val = $(this).val(); - if($val == "") $val = $(this).attr("placeholder"); - $(this).closest(".sp-custom-value").hide().siblings(".sp-default-value").show().find(".sp-default-value-input").html($val); - }); - - // Define custom value editor cancellation - $(".sp-data-table .sp-custom-value .sp-custom-value-input").on("cancelInput", function() { - $val = $(this).closest(".sp-custom-value").siblings(".sp-default-value").find(".sp-default-value-input").html(); - if($val == $(this).attr("placeholder")) $(this).val(""); - else $(this).val($val); - $(this).closest(".sp-custom-value").hide().siblings(".sp-default-value").show(); - }); - - // Custom value editor save - $(".sp-data-table .sp-custom-value .sp-save").click(function() { - $(this).siblings(".sp-custom-value-input").trigger("saveInput"); - }); - - // Custom value editor cancel - $(".sp-data-table .sp-custom-value .sp-cancel").click(function() { - $(this).siblings(".sp-custom-value-input").trigger("cancelInput"); - }); - - // Prevent custom value editor input from submitting form - $(".sp-data-table .sp-custom-value .sp-custom-value-input").keypress(function(event) { - if(event.keyCode == 13){ - event.preventDefault(); - $(this).trigger("saveInput"); - return false; - } - }); - - // Cancel custom value editor form on escape - $(".sp-data-table .sp-custom-value .sp-custom-value-input").keyup(function(event) { - if(event.keyCode == 27){ - event.preventDefault(); - $(this).trigger("cancelInput"); - return false; - } - }); - - // Data table adjustments - $(".sp-table-adjustments input").change(function() { - matrix = $(this).attr("data-matrix"); - $el = $(this).closest(".sp-table-adjustments").siblings(".sp-table-values").find("input[data-matrix="+matrix+"]"); - placeholder = $el.attr("data-placeholder"); - current_adjustment = parseFloat($el.attr("data-adjustment")); - adjustment = parseFloat($(this).val()); - if(! isNaN(adjustment) && adjustment != 0) { - placeholder = parseFloat(placeholder); - if(isNaN(placeholder)) placeholder = 0; - if(isNaN(current_adjustment)) current_adjustment = 0; - placeholder += adjustment - current_adjustment; - } - $el.attr("placeholder", placeholder); - }).change(); - - // Data table keyboard navigation - $(".sp-data-table tbody tr td input:text").keydown(function(event) { - if(! $(this).parent().hasClass("chosen-search") && [37,38,39,40].indexOf(event.keyCode) > -1){ - $el = $(this).closest("td"); - var col = $el.parent().children().index($el)+1; - var row = $el.parent().parent().children().index($el.parent())+1; - if(event.keyCode == 37){ - if ( $(this).caret().start != 0 ) - return true; - col -= 1; + ); + $( ".sp-desc-tip" ).tipTip( + { + delay: 200, + fadeIn: 100, + fadeOut: 100, + defaultPosition: 'right' } - if(event.keyCode == 38){ - row -= 1; - } - if(event.keyCode == 39){ - if ( $(this).caret().start != $(this).val().length ) - return true; - col += 1; - } - if(event.keyCode == 40){ - row += 1; - } - $el.closest("tbody").find("tr:nth-child("+row+") td:nth-child("+col+") input:text").first().focus(); - } - }); + ); - // Prevent data table from submitting form - $(".sp-data-table tbody tr td input:text").keypress(function(event) { - if(! $(this).parent().hasClass("chosen-search") && event.keyCode == 13){ - event.preventDefault(); - $el = $(this).closest("td"); - var col = $el.parent().children().index($el)+1; - var row = $el.parent().parent().children().index($el.parent())+2; - $el.closest("tbody").find("tr:nth-child("+row+") td:nth-child("+col+") input:text").focus(); - return false; - } - }); - - // Total stats calculator - $(".sp-data-table .sp-total input[data-sp-format=number][data-sp-total-type!=average]").on("updateTotal", function() { - index = $(this).parent().index(); - var sum = 0; - $(this).closest(".sp-data-table").find(".sp-post").each(function() { - val = $(this).find("td").eq(index).find("input").val(); - if(val == "") { - val = $(this).find("td").eq(index).find("input").attr("placeholder"); - } - if($.isNumeric(val)) { - sum += parseFloat(val, 10); - } - }); - $(this).attr("placeholder", sum); - }); - - // Activate total stats calculator - if($(".sp-data-table .sp-total").length) { - $(".sp-data-table .sp-post td input").on("keyup", function() { - $(this).closest(".sp-data-table").find(".sp-total td").eq($(this).parent().index()).find("input[data-sp-format=number][data-sp-total-type!=average]").trigger("updateTotal"); - }); - } - - // Trigger total stats calculator - $(".sp-data-table .sp-total input[data-sp-format=number][data-sp-total-type!=average]").trigger("updateTotal"); - - // Sync inputs - $(".sp-sync-input").on("keyup", function() { - name = $(this).attr("name"); - $el = $("input[name='"+name+"']"); - if ( $el.length > 1 ) { - val = $(this).val(); - $el.val(val); - } - }); - - // Sync selects - $(".sp-sync-select").on("change", function() { - name = $(this).attr("name"); - $el = $("select[name='"+name+"']") - if ( $el.length > 1 ) { - val = $(this).val(); - $el.val(val); - } - }); - - // Select all checkboxes - $(".sp-select-all-range").on("change", ".sp-select-all", function() { - $range = $(this).closest(".sp-select-all-range"); - $range.find("input[type=checkbox]").prop("checked", $(this).prop("checked")); - }); - - // Check if all checkboxes are checked already - $(".sp-select-all-range").on("checkCheck", function() { - $(this).each(function() { - $(this).find(".sp-select-all").prop("checked", $(this).find("input[type=checkbox]:checked:not(.sp-select-all)").length != 0 && $(this).find("input[type=checkbox]:checked:not(.sp-select-all)").length == $(this).find("input[type=checkbox]:visible:not(.sp-select-all)").length); - }); - }); - - // Activate check check when a checkbox is checked - $(".sp-select-all-range input[type=checkbox]:not(.sp-select-all)").change(function() { - $(this).closest(".sp-select-all-range").trigger("checkCheck"); - }); - - // Activate check check on page load - $(".sp-select-all-range").trigger("checkCheck"); - - // Trigger check check - $(".sp-data-table").trigger("checkCheck"); - - // Sortable tables - $(".sp-sortable-table tbody").sortable({ - handle: ".icon", - axis: "y" - }); - - // Sortable lists - $( ".sp-sortable-list" ).sortable({ - handle: ".sp-item-handle", - placeholder: "sp-item-placeholder", - connectWith: ".sp-connected-list" - }); - - // Autosave - $(".sp-autosave").change(function() { - $(this).attr("readonly", true).closest("form").submit(); - }); - - // Video embed - $(".sp-add-video").click(function() { - $(this).closest("fieldset").hide().siblings(".sp-video-field").show(); - return false; - }); - - // Removing video embed - $(".sp-remove-video").click(function() { - $(this).closest("fieldset").hide().siblings(".sp-video-adder").show().siblings(".sp-video-field").find("input").val(null); - return false; - }); - - // Equation selector - $(".sp-equation-selector select:last").change(function() { - $(this).siblings().change(function() { - if($(this).val() == "") $(this).remove(); - }).find("option:first").text(localized_strings.remove_text); - if($(this).val() != "") { - $(this).before($(this).clone().val($(this).val())).val("").change(); - } - }); - - // Trigger equation selector - $(".sp-equation-selector select:last").change().siblings().change(); - - // Order selector - $(".sp-order-selector select:first").change(function() { - if($(this).val() == "0") { - $(this).siblings().prop( "disabled", true ); - } else { - $(this).siblings().prop( "disabled", false ) - } - }); - - // Trigger order selector - $(".sp-order-selector select:first").change(); - - // Format selector - $(".sp-format-selector select:first").change(function() { - - $precisiondiv = $("#sp_precisiondiv"); - $precisioninput = $("#sp_precision"); - $timeddiv = $("#sp_timeddiv"); - $equationdiv = $("#sp_equationdiv"); - - // Equation settings - if ($(this).val() == "equation") { - $equationdiv.show(); - $precisiondiv.show(); - $timeddiv.hide(); - $precisioninput.prop( "disabled", false ); - } else if ($(this).val() == "number") { - $equationdiv.hide(); - $precisiondiv.hide(); - $timeddiv.show(); - $precisioninput.prop( "disabled", true ); - } else { - $equationdiv.hide(); - $precisiondiv.hide(); - $timeddiv.hide(); - $precisioninput.prop( "disabled", true ); - } - - }); - - // Trigger format selector - $(".sp-format-selector select:first").change(); - - // Team era selector - $(".sp-team-era-selector select:first-child").change(function() { - - $subselector = $(this).siblings(); - - // Sub settings - if($(this).val() == 0) { - $subselector.hide(); - } else { - $subselector.show(); - } - - }); - - // Trigger team era selector - $(".sp-team-era-selector select:first-child").change(); - - // Status selector - $(".sp-status-selector select:first-child").change(function() { - - $subselector = $(this).siblings(); - - // Sub settings - if($(this).val() == "sub") { - $subselector.show(); - } else { - $subselector.hide(); - } - - }); - - // Trigger status selector - $(".sp-status-selector select:first-child").change(); - - // Preset field modifier - $(".sp-custom-input-wrapper .preset").click(function() { - val = $(this).val(); - if(val == "\\c\\u\\s\\t\\o\\m") return true; - example = $(this).attr("data-example"); - $(this).closest(".sp-custom-input-wrapper").find(".value").val(val).siblings(".example").html(example); - }); - - // Select custom preset when field is brought to focus - $(".sp-custom-input-wrapper .value").focus(function() { - $(this).siblings("label").find(".preset").prop("checked", true); - }); - - // Adjust example field when custom preset is entered - $(".sp-custom-input-wrapper .value").on("keyup", function() { - val = $(this).val(); - if ( val === undefined ) return true; - format = $(this).attr("data-example-format"); - example = format.replace("__val__", val); - $(this).siblings(".example").html(example); - }); - - // Prevent address input from submitting form - $(".sp-address").keypress(function(event) { - return event.keyCode != 13; - }); - - // Dashboard countdown - $("#sportspress_dashboard_status .sp_status_list li.countdown").each(function() { - var $this = $(this); - // Get countdown time - var countDownDate = new Date($(this).data('countdown')).getTime(); - // Iterate every second - var x = setInterval(function() { - - // Get todays date and time - var now = new Date(); - - // Convert curent date and time to UTC - var tzDifference = now.getTimezoneOffset(); - var nowutc = new Date(now.getTime() + tzDifference * 60 * 1000); - - // Find the distance between now and the count down date - var distance = countDownDate - nowutc; - if ( distance < 0 ) { - distance = 0; - } - - // Time calculations for days, hours, minutes and seconds - var days = Math.floor(distance / (1000 * 60 * 60 * 24)); - var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); - var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); - var seconds = Math.floor((distance % (1000 * 60)) / 1000); - - // Output the result - $this.find('strong').html(days+" "+localized_strings.days+" "+('0' + hours).slice(-2)+":"+('0' + minutes).slice(-2)+":"+('0' + seconds).slice(-2)); - }, 1000); - }); - - // Event format affects data - $(".post-type-sp_event #post-formats-select").change(function() { - layout = $(".post-type-sp_event #post-formats-select input:checked").val(); - if ( layout == "friendly" ) { - $(".sp_event-sp_league-field").hide().find("select").prop("disabled", true); - $(".sp_event-sp_season-field").hide().find("select").prop("disabled", true); - } else { - $(".sp_event-sp_league-field").show().find("select").prop("disabled", false); - $(".sp_event-sp_season-field").show().find("select").prop("disabled", false); - } - }); - - // Trigger event format change - $(".post-type-sp_event #post-formats-select").trigger("change"); - - // Calendar layout affects data - $(".post-type-sp_calendar #post-formats-select").change(function() { - layout = $(".post-type-sp_calendar #post-formats-select input:checked").val(); - $(".sp-calendar-table tr").each(function() { - if ( layout == "list" ) { - $(this).find("th input[type=checkbox]").show(); - $(this).find("th select").prop("disabled", false); - } else { - $(this).find("th input[type=checkbox]").hide(); - $(this).find("th select").prop('selectedIndex', 0).prop("disabled", true); - } - }); - }); - - // Trigger calendar layout change - $(".post-type-sp_calendar #post-formats-select").trigger("change"); - - // Player list layout affects data - $(".post-type-sp_list #post-formats-select").change(function() { - layout = $(".post-type-sp_list #post-formats-select input:checked").val(); - $(".sp-player-list-table tr").each(function() { - if ( layout == "list" ) { - $(this).find("th input[type=checkbox]").show(); - } else { - $(this).find("th input[type=checkbox]").hide(); - } - }); - }); - - // Trigger player list layout change - $(".post-type-sp_list #post-formats-select").trigger("change"); - - // Configure primary result option (Ajax) - $(".sp-admin-config-table").on("click", ".sp-primary-result-option", function() { - $.post( ajaxurl, { - action: "sp-save-primary-result", - primary_result: $(this).val(), - nonce: $("#sp-primary-result-nonce").val() - }); - }); - - // Configure primary performance option (Ajax) - $(".sp-admin-config-table").on("click", ".sp-primary-performance-option", function() { - $.post( ajaxurl, { - action: "sp-save-primary-performance", - primary_performance: $(this).val(), - nonce: $("#sp-primary-performance-nonce").val() - }); - }); - - // Update importer post count - $(".sp-import-table").on("updatePostCount", function() { - $(".sp-post-count").text(localized_strings.displaying_posts.replace("%s", 1).replace(/%s/g, count = $(this).find("tbody tr").length)); - }); - - // Delete importer row - $(".sp-import-table").on("click", ".sp-delete-row", function() { - $self = $(this); - $self.closest("tr").css("background-color", "#f99").fadeOut(400, function() { - $table = $self.closest(".sp-import-table"); - $(this).remove(); - $table.trigger("updatePostCount"); - }); - return false; - }); - - // Add importer row - $(".sp-import-table").on("click", ".sp-add-row", function() { - $self = $(this); - $table = $self.closest(".sp-import-table"); - if ( $self.hasClass("sp-add-first") ) { - $tr = $table.find("tbody tr:first-child"); - $row = $tr.clone(); - $row.insertBefore($tr).find("input").val(""); - } else { - $tr = $self.closest("tr"); - $row = $tr.clone(); - $tr.find("input").val(""); - $row.insertBefore($tr); - } - $table.trigger("updatePostCount"); - return false; - }); - - // Enable or disable importer inputs based on column label - $(".sp-import-table").on("change", "select", function() { - $self = $(this); - $table = $self.closest(".sp-import-table"); - index = parseInt($self.data("index")); - if ( $self.val() == 0 ) { - $table.find("tbody tr td:nth-child("+parseInt(index+1)+") input").prop("disabled", true); - } else { - $table.find("tbody tr td:nth-child("+parseInt(index+1)+") input").prop("disabled", false); - $self.closest("th").siblings().find("select").each(function() { - if ( $(this).val() == $self.val() ) $(this).val("0").trigger("change"); - }); - } - }); - - // Datepicker - $(".sp-datepicker").datepicker({ - dateFormat : "yy-mm-dd" - }); - $(".sp-datepicker-from").datepicker({ - dateFormat : "yy-mm-dd", - onClose: function( selectedDate ) { - $(this).closest(".sp-date-selector").find(".sp-datepicker-to").datepicker("option", "minDate", selectedDate); - } - }); - $(".sp-datepicker-to").datepicker({ - dateFormat : "yy-mm-dd", - onClose: function( selectedDate ) { - $(this).closest(".sp-date-selector").find(".sp-datepicker-from").datepicker("option", "maxDate", selectedDate); - } - }); - - // Show or hide datepicker - $(".sp-date-selector select").change(function() { - if ( $(this).val() == "range" ) { - $(this).closest(".sp-date-selector").find(".sp-date-range").show(); - } else { - $(this).closest(".sp-date-selector").find(".sp-date-range").hide(); - } - }); - $(".sp-date-selector select").trigger("change"); - - // Toggle date range selectors - $(".sp-date-relative input").change(function() { - $relative = $(this).closest(".sp-date-relative").siblings(".sp-date-range-relative").toggle(0, $(this).attr("checked")); - $absolute = $(this).closest(".sp-date-relative").siblings(".sp-date-range-absolute").toggle(0, $(this).attr("checked")); - - if ($(this).attr("checked")) { - $relative.show(); - $absolute.hide(); - } else { - $absolute.show(); - $relative.hide(); - } - }); - $(".sp-date-selector input").trigger("change"); - - // Apply color scheme - $(".sp-color-option").on("click", function() { - colors = $(this).find("label").data("sp-colors").split(","); - $(".sp-custom-colors").find(".sp-color-box").each(function(index) { - $(this).find("input").val("#"+colors[index]).css("background-color", "#"+colors[index]); - });; - }); - - // Edit inline results - $("#the-list").on("click, focus", ".sp-result, .sp-edit-results", function(){ - team = $(this).data("team"); - $column = $(this).closest(".column-sp_team"); - $column.find(".sp-result, .sp-row-actions").hide(); - $column.find(".sp-edit-result, .sp-inline-edit-save").show(); - if ( team != undefined ) { - $column.find(".sp-edit-result[data-team='"+team+"']").select(); - } - return false; - }); - - // Cancel inline results - $("#the-list").on("click", ".sp-inline-edit-save .cancel", function(){ - $column = $(this).closest(".column-sp_team"); - $column.find(".sp-edit-result, .sp-inline-edit-save").hide(); - $column.find(".sp-result, .sp-row-actions").show(); - return false; - }); - - // Save inline results - $("#the-list").on("click", ".sp-inline-edit-save .save", function(){ - $column = $(this).closest(".column-sp_team"); - results = {}; - $column.find(".sp-edit-result").each(function() { - id = $(this).data("team"); - result = $(this).val(); - results[id] = result; - }); - $.post( ajaxurl, { - action: "sp-save-inline-results", - post_id: $column.find("input[name='sp_post_id']").val(), - results: results, - nonce: $("#sp-inline-nonce").val() - }, function(response) { - $column.find(".sp-edit-result").each(function() { - val = $(this).val(); - $column.find(".sp-result[data-team='"+$(this).data("team")+"']").html(val==''?'-':val); - }); - $column.find(".sp-edit-result, .sp-inline-edit-save").hide(); - $column.find(".sp-result, .sp-row-actions").show(); - return false; - }); - }); - - // Override inline form submission - $("#the-list").on("keypress", ".sp-edit-result", function(e) { - if ( e.which == 13 ) { - $(this).closest(".column-sp_team").find(".sp-inline-edit-save .save").trigger("click"); - return false; - } - }); - - // Fitvids - $(".sp-fitvids").fitVids(); - - // Display configure sport button - $(".sp-select-sport").change(function() { - $(".sp-configure-sport").hide(); - }); - - // Ajax checklist - $(".sp-ajax-checklist").siblings(".sp-tab-select").find("select").change(function() { - $(this).closest(".sp-tab-select").siblings(".sp-ajax-checklist").find("ul").html("
  • " + localized_strings.loading + "
  • "); - $.post( ajaxurl, { - action: "sp-get-players", - team: $(this).val(), - league: ('yes' == localized_strings.option_filter_by_league) ? $("select[name=\"tax_input[sp_league][]\"]").val() : null, - season: ('yes' == localized_strings.option_filter_by_season) ? $("select[name=\"tax_input[sp_season][]\"]").val() : null, - index: $(this).closest(".sp-instance").index(), - nonce: $("#sp-get-players-nonce").val() - }).done(function( response ) { - index = response.data.index; - $target = $(".sp-instance").eq(index).find(".sp-ajax-checklist ul"); - if ( response.success ) { - $target.html(""); - i = 0; - if(-1 == response.data.sections) { - if(response.data.players.length) { - $target.eq(0).append("
  • "); - $(response.data.players).each(function( key, value ) { - $target.eq(0).append("
  • "); - }); - $target.eq(0).append("
  • " + localized_strings.show_all + "
  • "); - } else { - $target.eq(0).html("
  • " + localized_strings.no_results_found + " " + localized_strings.show_all + "
  • "); + // Chosen select + $( document ).on( + "postbox-toggled", + function() { + $( ".chosen-select" ).filter( ":visible" ).chosen( + { + allow_single_deselect: true, + search_contains: true, + single_backstroke_delete: false, + disable_search_threshold: 10, + placeholder_text_multiple: localized_strings.none } + ); + } + ).trigger( "postbox-toggled" ); + + // Auto key placeholder + $( "#poststuff #title" ).on( + "keyup", + function() { + val = $( this ).val() + lc = val.replace( /[^a-z]/gi,"" ).toLowerCase(); + $( "#sp_key" ).attr( "placeholder", lc ); + $( "#sp_default_key" ).val( lc ); + $( "#sp_singular" ).attr( "placeholder", val ); + } + ); + + // Activate auto key placeholder + $( "#poststuff #title" ).keyup(); + + // Radio input toggle + $( ".sp-radio-toggle" ).click( + function() { + if ($( this ).data( "sp-checked" )) { + $( this ).prop( "checked", false ); + $( this ).data( "sp-checked", false ); } else { - if ( 1 == response.data.sections ) { - defense = i; - offense = i+1; - } else { - offense = i; - defense = i+1; - } - if(response.data.players.length) { - $target.eq(offense).append("
  • "); - $target.eq(defense).append("
  • "); - $(response.data.players).each(function( key, value ) { - $target.eq(offense).append("
  • "); - $target.eq(defense).append("
  • "); - }); - $target.eq(offense).append("
  • " + localized_strings.show_all + "
  • "); - $target.eq(defense).append("
  • " + localized_strings.show_all + "
  • "); - } else { - $target.eq(offense).html("
  • " + localized_strings.no_results_found + " " + localized_strings.show_all + "
  • "); - $target.eq(defense).html("
  • " + localized_strings.no_results_found + " " + localized_strings.show_all + "
  • "); - } - i++; + $( this ).data( "sp-checked", true ); } - i++; - if(response.data.staff.length) { - $target.eq(i).append("
  • "); - $(response.data.staff).each(function( key, value ) { - $target.eq(i).append("
  • "); - }); - $target.eq(i).append("
  • " + localized_strings.show_all + "
  • "); - } else { - $target.eq(i).html("
  • " + localized_strings.no_results_found + " " + localized_strings.show_all + "
  • "); - } - } else { - $target.html("
  • " + localized_strings.no_results_found + "
  • "); } - }); - }); + ); - // Activate Ajax trigger - $(".sp-ajax-trigger").change(function() { - $(".sp-ajax-checklist").siblings(".sp-tab-select").find("select").change(); - }); + // Table switcher + $( ".sp-table-panel" ).siblings( ".sp-table-bar" ).find( "a" ).click( + function() { + $( this ).closest( "li" ).find( "a" ).addClass( "current" ).closest( "li" ).siblings().find( "a" ).removeClass( "current" ).closest( ".sp-table-bar" ).siblings( $( this ).attr( "href" ) ).show().siblings( ".sp-table-panel" ).hide(); + return false; + } + ); - // Ajax show all filter - $(".sp-tab-panel").on("click", ".sp-ajax-show-all", function() { - index = $(this).closest(".sp-instance").index(); - $(this).parent().html(localized_strings.loading); - $.post( ajaxurl, { - action: "sp-get-players", - index: index, - nonce: $("#sp-get-players-nonce").val() - }).done(function( response ) { - index = response.data.index; - console.log(index); - $target = $(".sp-instance").eq(index).find(".sp-ajax-checklist ul"); - $target.find(".sp-ajax-show-all-container").hide(); - if ( response.success ) { - i = 0; - console.log(response.data.sections); - if ( -1 == response.data.sections ) { - if(response.data.players.length) { - $(response.data.players).each(function( key, value ) { - if($target.eq(i).find("input[value=" + value.ID + "]").length) return true; - $target.eq(i).append("
  • "); - }); - } else { - $target.eq(i).html("
  • " + localized_strings.no_results_found + "
  • "); - } - } else { - if(response.data.players.length) { - if ( 1 == response.data.sections ) { - defense = i; - offense = i+1; - } else { - offense = i; - defense = i+1; + // Tab switcher + $( ".sp-tab-panel" ).siblings( ".sp-tab-bar" ).find( "a" ).click( + function() { + $( this ).closest( "li" ).addClass( "tabs" ).siblings().removeClass( "tabs" ).closest( ".sp-tab-bar" ).siblings( $( this ).attr( "href" ) ).show().trigger( 'checkCheck' ).siblings( ".sp-tab-panel" ).hide(); + return false; + } + ); + + // Tab filter + $( ".sp-tab-filter-panel" ).siblings( ".sp-tab-select" ).find( "select" ).change( + function() { + var val = $( this ).val(); + var filter = ".sp-filter-" + val; + var $filters = $( this ).closest( ".sp-tab-select" ).siblings( ".sp-tab-select" ); + if ($filters.length) { + $filters.each( + function() { + filterval = $( this ).find( "select" ).val(); + if (filterval !== undefined) { + filter += ".sp-filter-" + filterval; + } + } + ); + } + $panel = $( this ).closest( ".sp-tab-select" ).siblings( ".sp-tab-panel" ); + $panel.each( + function() { + $( this ).find( ".sp-post" ).hide( + 0, + function() { + $( this ).find( "input" ).prop( "disabled", true ); + $( this ).filter( filter ).show( + 0, + function() { + $( this ).find( "input" ).prop( "disabled", false ); + } + ); + } + ); + if ($( this ).find( ".sp-post:visible" ).length > 0) { + $( this ).find( ".sp-select-all-container" ).show(); + $( this ).find( ".sp-show-all-container" ).show(); + $( this ).find( ".sp-not-found-container" ).hide(); + } else { + $( this ).find( ".sp-select-all-container" ).hide(); + $( this ).find( ".sp-show-all-container" ).hide(); + $( this ).find( ".sp-not-found-container" ).show(); } - $(response.data.players).each(function( key, value ) { - $target.eq(offense).append("
  • "); - $target.eq(defense).append("
  • "); - }); - } else { - $target.eq(offense).html("
  • " + localized_strings.no_results_found + "
  • "); - $target.eq(defense).html("
  • " + localized_strings.no_results_found + "
  • "); } - i++; - } - i++; - if(response.data.staff.length) { - $(response.data.staff).each(function( key, value ) { - $target.eq(i).append("
  • "); - }); - } else { - $target.eq(i).html("
  • " + localized_strings.no_results_found + "
  • "); - } - } else { - $target.html("
  • " + localized_strings.no_results_found + "
  • "); + ); } - }); - }); + ); - // Event status selector - $('.sp-edit-event-status').click(function(e) { - e.preventDefault(); - $select = $(this).siblings('.sp-event-status-select'); - if ( $select.is(':hidden') ) { - $select.slideDown( 'fast', function() { - $select.find( 'input[type="radio"]' ).first().focus(); - } ); - $(this).hide(); + // Trigger tab filter + $( ".sp-tab-filter-panel" ).siblings( ".sp-tab-select" ).find( "select" ).change(); + + // Dropdown filter + $( ".sp-dropdown-target" ).siblings( ".sp-dropdown-filter" ).find( "select" ).change( + function() { + var val = $( this ).val(); + var filter = ".sp-filter-" + val; + var $filters = $( this ).closest( ".sp-dropdown-filter" ).siblings( ".sp-dropdown-filter" ); + if ($filters.length) { + $filters.each( + function() { + filterval = $( this ).find( "select" ).val(); + if (filterval !== undefined) { + filter += ".sp-filter-" + filterval; + } + } + ); + } + $target = $( this ).closest( ".sp-dropdown-filter" ).siblings( ".sp-dropdown-target" ).find( "select" ); + $target.find( ".sp-post" ).prop( "disabled", true ).each( + function() { + $( this ).filter( filter ).prop( "disabled", false ); + } + ); + } + ); + + // Trigger dropdown filter + $( ".sp-dropdown-target" ).siblings( ".sp-dropdown-filter" ).find( "select" ).change(); + + // Filter show all action links + $( ".sp-tab-panel" ).find( ".sp-post input:checked" ).each( + function() { + $( this ).prop( "disabled", false ).closest( "li" ).show().siblings( ".sp-not-found-container" ).hide().siblings( ".sp-show-all-container" ).show(); + } + ); + + // Show all filter + $( ".sp-tab-panel" ).on( + "click", + ".sp-show-all", + function() { + $( this ).closest( "li" ).hide().siblings( ".sp-post, .sp-select-all-container" ).show().find( "input" ).prop( "disabled", false ); + } + ); + + // Self-cloning + $( ".sp-clone:last" ).find( "select" ).change( + function() { + $( this ).closest( ".sp-clone" ).siblings().find( "select" ).change( + function() { + if ($( this ).val() == "0") { + $( this ).closest( ".sp-clone" ).remove(); + } + } + ).find( "option:first" ).text( localized_strings.remove_text ); + if ($( this ).val() != "0") { + $original = $( this ).closest( ".sp-clone" ); + $original.before( $original.clone().find( "select" ).attr( "name", $original.attr( "data-clone-name" ) + "[]" ).val( $( this ).val() ).closest( ".sp-clone" ) ).attr( "data-clone-num", parseInt( $original.attr( "data-clone-num" ) ) + 1 ).find( "select" ).val( "0" ).change(); + } + } + ); + + // Activate self-cloning + $( ".sp-clone:last" ).find( "select" ).change(); + + // Custom value editor + $( ".sp-data-table .sp-default-value" ).click( + function() { + $( this ).hide().siblings( ".sp-custom-value" ).show().find( ".sp-custom-value-input" ).focus(); + } + ); + + // Define custom value editor saving + $( ".sp-data-table .sp-custom-value .sp-custom-value-input" ).on( + "saveInput", + function() { + $val = $( this ).val(); + if ($val == "") { + $val = $( this ).attr( "placeholder" ); + } + $( this ).closest( ".sp-custom-value" ).hide().siblings( ".sp-default-value" ).show().find( ".sp-default-value-input" ).html( $val ); + } + ); + + // Define custom value editor cancellation + $( ".sp-data-table .sp-custom-value .sp-custom-value-input" ).on( + "cancelInput", + function() { + $val = $( this ).closest( ".sp-custom-value" ).siblings( ".sp-default-value" ).find( ".sp-default-value-input" ).html(); + if ($val == $( this ).attr( "placeholder" )) { + $( this ).val( "" ); + } else { + $( this ).val( $val ); + } + $( this ).closest( ".sp-custom-value" ).hide().siblings( ".sp-default-value" ).show(); + } + ); + + // Custom value editor save + $( ".sp-data-table .sp-custom-value .sp-save" ).click( + function() { + $( this ).siblings( ".sp-custom-value-input" ).trigger( "saveInput" ); + } + ); + + // Custom value editor cancel + $( ".sp-data-table .sp-custom-value .sp-cancel" ).click( + function() { + $( this ).siblings( ".sp-custom-value-input" ).trigger( "cancelInput" ); + } + ); + + // Prevent custom value editor input from submitting form + $( ".sp-data-table .sp-custom-value .sp-custom-value-input" ).keypress( + function(event) { + if (event.keyCode == 13) { + event.preventDefault(); + $( this ).trigger( "saveInput" ); + return false; + } + } + ); + + // Cancel custom value editor form on escape + $( ".sp-data-table .sp-custom-value .sp-custom-value-input" ).keyup( + function(event) { + if (event.keyCode == 27) { + event.preventDefault(); + $( this ).trigger( "cancelInput" ); + return false; + } + } + ); + + // Data table adjustments + $( ".sp-table-adjustments input" ).change( + function() { + matrix = $( this ).attr( "data-matrix" ); + $el = $( this ).closest( ".sp-table-adjustments" ).siblings( ".sp-table-values" ).find( "input[data-matrix=" + matrix + "]" ); + placeholder = $el.attr( "data-placeholder" ); + current_adjustment = parseFloat( $el.attr( "data-adjustment" ) ); + adjustment = parseFloat( $( this ).val() ); + if ( ! isNaN( adjustment ) && adjustment != 0) { + placeholder = parseFloat( placeholder ); + if (isNaN( placeholder )) { + placeholder = 0; + } + if (isNaN( current_adjustment )) { + current_adjustment = 0; + } + placeholder += adjustment - current_adjustment; + } + $el.attr( "placeholder", placeholder ); + } + ).change(); + + // Data table keyboard navigation + $( ".sp-data-table tbody tr td input:text" ).keydown( + function(event) { + if ( ! $( this ).parent().hasClass( "chosen-search" ) && [37,38,39,40].indexOf( event.keyCode ) > -1) { + $el = $( this ).closest( "td" ); + var col = $el.parent().children().index( $el ) + 1; + var row = $el.parent().parent().children().index( $el.parent() ) + 1; + if (event.keyCode == 37) { + if ( $( this ).caret().start != 0 ) { + return true; + } + col -= 1; + } + if (event.keyCode == 38) { + row -= 1; + } + if (event.keyCode == 39) { + if ( $( this ).caret().start != $( this ).val().length ) { + return true; + } + col += 1; + } + if (event.keyCode == 40) { + row += 1; + } + $el.closest( "tbody" ).find( "tr:nth-child(" + row + ") td:nth-child(" + col + ") input:text" ).first().focus(); + } + } + ); + + // Prevent data table from submitting form + $( ".sp-data-table tbody tr td input:text" ).keypress( + function(event) { + if ( ! $( this ).parent().hasClass( "chosen-search" ) && event.keyCode == 13) { + event.preventDefault(); + $el = $( this ).closest( "td" ); + var col = $el.parent().children().index( $el ) + 1; + var row = $el.parent().parent().children().index( $el.parent() ) + 2; + $el.closest( "tbody" ).find( "tr:nth-child(" + row + ") td:nth-child(" + col + ") input:text" ).focus(); + return false; + } + } + ); + + // Total stats calculator + $( ".sp-data-table .sp-total input[data-sp-format=number][data-sp-total-type!=average]" ).on( + "updateTotal", + function() { + index = $( this ).parent().index(); + var sum = 0; + $( this ).closest( ".sp-data-table" ).find( ".sp-post" ).each( + function() { + val = $( this ).find( "td" ).eq( index ).find( "input" ).val(); + if (val == "") { + val = $( this ).find( "td" ).eq( index ).find( "input" ).attr( "placeholder" ); + } + if ($.isNumeric( val )) { + sum += parseFloat( val, 10 ); + } + } + ); + $( this ).attr( "placeholder", sum ); + } + ); + + // Activate total stats calculator + if ($( ".sp-data-table .sp-total" ).length) { + $( ".sp-data-table .sp-post td input" ).on( + "keyup", + function() { + $( this ).closest( ".sp-data-table" ).find( ".sp-total td" ).eq( $( this ).parent().index() ).find( "input[data-sp-format=number][data-sp-total-type!=average]" ).trigger( "updateTotal" ); + } + ); } - }); - $('.sp-save-event-status').click(function(e) { - e.preventDefault(); - $select = $(this).closest('.sp-event-status-select'); - $input = $select.find('input[name=sp_status]:checked'); - val = $input.val(); - label = $input.data('sp-event-status'); - $select.slideUp('fast').siblings('.sp-edit-event-status').show().siblings('.sp-event-status').find('.sp-event-status-display').data('sp-event-status', val).html(label); - }); + // Trigger total stats calculator + $( ".sp-data-table .sp-total input[data-sp-format=number][data-sp-total-type!=average]" ).trigger( "updateTotal" ); - $('.sp-cancel-event-status').click(function(e) { - e.preventDefault(); - $select = $(this).closest('.sp-event-status-select'); - val = $select.siblings('.sp-event-status').find('.sp-event-status-display').data('sp-event-status'); - $select.find('input[value='+val+']').attr('checked', true); - $select.slideUp('fast').siblings('.sp-edit-event-status').show(); - }); + // Sync inputs + $( ".sp-sync-input" ).on( + "keyup", + function() { + name = $( this ).attr( "name" ); + $el = $( "input[name='" + name + "']" ); + if ( $el.length > 1 ) { + val = $( this ).val(); + $el.val( val ); + } + } + ); - // Box score time converter - $('.sp-convert-time-input').change(function() { - var s = 0; - var val = $(this).val(); - if (val === '') { - $(this).siblings('.sp-convert-time-output').val(''); - return; - } - var a = val.split(':').reverse(); - $.each(a, function( index, value ) { - s += parseInt(value) * Math.pow(60, index); - }); - $(this).siblings('.sp-convert-time-output').val(s); - }); + // Sync selects + $( ".sp-sync-select" ).on( + "change", + function() { + name = $( this ).attr( "name" ); + $el = $( "select[name='" + name + "']" ) + if ( $el.length > 1 ) { + val = $( this ).val(); + $el.val( val ); + } + } + ); - // Trigger box score time converter - $('.sp-convert-time-input').change(); - - // Trigger show/hide of team table ordering - $('#sp_orderby').change(function(){ - if ($('#sp_orderby').val() == 'default') { - $("#sp_order").hide(); - }else{ - $('#sp_order').show(); - } - }); -}); \ No newline at end of file + // Select all checkboxes + $( ".sp-select-all-range" ).on( + "change", + ".sp-select-all", + function() { + $range = $( this ).closest( ".sp-select-all-range" ); + $range.find( "input[type=checkbox]" ).prop( "checked", $( this ).prop( "checked" ) ); + } + ); + + // Check if all checkboxes are checked already + $( ".sp-select-all-range" ).on( + "checkCheck", + function() { + $( this ).each( + function() { + $( this ).find( ".sp-select-all" ).prop( "checked", $( this ).find( "input[type=checkbox]:checked:not(.sp-select-all)" ).length != 0 && $( this ).find( "input[type=checkbox]:checked:not(.sp-select-all)" ).length == $( this ).find( "input[type=checkbox]:visible:not(.sp-select-all)" ).length ); + } + ); + } + ); + + // Activate check check when a checkbox is checked + $( ".sp-select-all-range input[type=checkbox]:not(.sp-select-all)" ).change( + function() { + $( this ).closest( ".sp-select-all-range" ).trigger( "checkCheck" ); + } + ); + + // Activate check check on page load + $( ".sp-select-all-range" ).trigger( "checkCheck" ); + + // Trigger check check + $( ".sp-data-table" ).trigger( "checkCheck" ); + + // Sortable tables + $( ".sp-sortable-table tbody" ).sortable( + { + handle: ".icon", + axis: "y" + } + ); + + // Sortable lists + $( ".sp-sortable-list" ).sortable( + { + handle: ".sp-item-handle", + placeholder: "sp-item-placeholder", + connectWith: ".sp-connected-list" + } + ); + + // Autosave + $( ".sp-autosave" ).change( + function() { + $( this ).attr( "readonly", true ).closest( "form" ).submit(); + } + ); + + // Video embed + $( ".sp-add-video" ).click( + function() { + $( this ).closest( "fieldset" ).hide().siblings( ".sp-video-field" ).show(); + return false; + } + ); + + // Removing video embed + $( ".sp-remove-video" ).click( + function() { + $( this ).closest( "fieldset" ).hide().siblings( ".sp-video-adder" ).show().siblings( ".sp-video-field" ).find( "input" ).val( null ); + return false; + } + ); + + // Equation selector + $( ".sp-equation-selector select:last" ).change( + function() { + $( this ).siblings().change( + function() { + if ($( this ).val() == "") { + $( this ).remove(); + } + } + ).find( "option:first" ).text( localized_strings.remove_text ); + if ($( this ).val() != "") { + $( this ).before( $( this ).clone().val( $( this ).val() ) ).val( "" ).change(); + } + } + ); + + // Trigger equation selector + $( ".sp-equation-selector select:last" ).change().siblings().change(); + + // Order selector + $( ".sp-order-selector select:first" ).change( + function() { + if ($( this ).val() == "0") { + $( this ).siblings().prop( "disabled", true ); + } else { + $( this ).siblings().prop( "disabled", false ) + } + } + ); + + // Trigger order selector + $( ".sp-order-selector select:first" ).change(); + + // Format selector + $( ".sp-format-selector select:first" ).change( + function() { + + $precisiondiv = $( "#sp_precisiondiv" ); + $precisioninput = $( "#sp_precision" ); + $timeddiv = $( "#sp_timeddiv" ); + $equationdiv = $( "#sp_equationdiv" ); + + // Equation settings + if ($( this ).val() == "equation") { + $equationdiv.show(); + $precisiondiv.show(); + $timeddiv.hide(); + $precisioninput.prop( "disabled", false ); + } else if ($( this ).val() == "number") { + $equationdiv.hide(); + $precisiondiv.hide(); + $timeddiv.show(); + $precisioninput.prop( "disabled", true ); + } else { + $equationdiv.hide(); + $precisiondiv.hide(); + $timeddiv.hide(); + $precisioninput.prop( "disabled", true ); + } + + } + ); + + // Trigger format selector + $( ".sp-format-selector select:first" ).change(); + + // Team era selector + $( ".sp-team-era-selector select:first-child" ).change( + function() { + + $subselector = $( this ).siblings(); + + // Sub settings + if ($( this ).val() == 0) { + $subselector.hide(); + } else { + $subselector.show(); + } + + } + ); + + // Trigger team era selector + $( ".sp-team-era-selector select:first-child" ).change(); + + // Status selector + $( ".sp-status-selector select:first-child" ).change( + function() { + + $subselector = $( this ).siblings(); + + // Sub settings + if ($( this ).val() == "sub") { + $subselector.show(); + } else { + $subselector.hide(); + } + + } + ); + + // Trigger status selector + $( ".sp-status-selector select:first-child" ).change(); + + // Preset field modifier + $( ".sp-custom-input-wrapper .preset" ).click( + function() { + val = $( this ).val(); + if (val == "\\c\\u\\s\\t\\o\\m") { + return true; + } + example = $( this ).attr( "data-example" ); + $( this ).closest( ".sp-custom-input-wrapper" ).find( ".value" ).val( val ).siblings( ".example" ).html( example ); + } + ); + + // Select custom preset when field is brought to focus + $( ".sp-custom-input-wrapper .value" ).focus( + function() { + $( this ).siblings( "label" ).find( ".preset" ).prop( "checked", true ); + } + ); + + // Adjust example field when custom preset is entered + $( ".sp-custom-input-wrapper .value" ).on( + "keyup", + function() { + val = $( this ).val(); + if ( val === undefined ) { + return true; + } + format = $( this ).attr( "data-example-format" ); + example = format.replace( "__val__", val ); + $( this ).siblings( ".example" ).html( example ); + } + ); + + // Prevent address input from submitting form + $( ".sp-address" ).keypress( + function(event) { + return event.keyCode != 13; + } + ); + + // Dashboard countdown + $( "#sportspress_dashboard_status .sp_status_list li.countdown" ).each( + function() { + var $this = $( this ); + // Get countdown time + var countDownDate = new Date( $( this ).data( 'countdown' ) ).getTime(); + // Iterate every second + var x = setInterval( + function() { + + // Get todays date and time + var now = new Date(); + + // Convert curent date and time to UTC + var tzDifference = now.getTimezoneOffset(); + var nowutc = new Date( now.getTime() + tzDifference * 60 * 1000 ); + + // Find the distance between now and the count down date + var distance = countDownDate - nowutc; + if ( distance < 0 ) { + distance = 0; + } + + // Time calculations for days, hours, minutes and seconds + var days = Math.floor( distance / (1000 * 60 * 60 * 24) ); + var hours = Math.floor( (distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60) ); + var minutes = Math.floor( (distance % (1000 * 60 * 60)) / (1000 * 60) ); + var seconds = Math.floor( (distance % (1000 * 60)) / 1000 ); + + // Output the result + $this.find( 'strong' ).html( days + " " + localized_strings.days + " " + ('0' + hours).slice( -2 ) + ":" + ('0' + minutes).slice( -2 ) + ":" + ('0' + seconds).slice( -2 ) ); + }, + 1000 + ); + } + ); + + // Event format affects data + $( ".post-type-sp_event #post-formats-select" ).change( + function() { + layout = $( ".post-type-sp_event #post-formats-select input:checked" ).val(); + if ( layout == "friendly" ) { + $( ".sp_event-sp_league-field" ).hide().find( "select" ).prop( "disabled", true ); + $( ".sp_event-sp_season-field" ).hide().find( "select" ).prop( "disabled", true ); + } else { + $( ".sp_event-sp_league-field" ).show().find( "select" ).prop( "disabled", false ); + $( ".sp_event-sp_season-field" ).show().find( "select" ).prop( "disabled", false ); + } + } + ); + + // Trigger event format change + $( ".post-type-sp_event #post-formats-select" ).trigger( "change" ); + + // Calendar layout affects data + $( ".post-type-sp_calendar #post-formats-select" ).change( + function() { + layout = $( ".post-type-sp_calendar #post-formats-select input:checked" ).val(); + $( ".sp-calendar-table tr" ).each( + function() { + if ( layout == "list" ) { + $( this ).find( "th input[type=checkbox]" ).show(); + $( this ).find( "th select" ).prop( "disabled", false ); + } else { + $( this ).find( "th input[type=checkbox]" ).hide(); + $( this ).find( "th select" ).prop( 'selectedIndex', 0 ).prop( "disabled", true ); + } + } + ); + } + ); + + // Trigger calendar layout change + $( ".post-type-sp_calendar #post-formats-select" ).trigger( "change" ); + + // Player list layout affects data + $( ".post-type-sp_list #post-formats-select" ).change( + function() { + layout = $( ".post-type-sp_list #post-formats-select input:checked" ).val(); + $( ".sp-player-list-table tr" ).each( + function() { + if ( layout == "list" ) { + $( this ).find( "th input[type=checkbox]" ).show(); + } else { + $( this ).find( "th input[type=checkbox]" ).hide(); + } + } + ); + } + ); + + // Trigger player list layout change + $( ".post-type-sp_list #post-formats-select" ).trigger( "change" ); + + // Configure primary result option (Ajax) + $( ".sp-admin-config-table" ).on( + "click", + ".sp-primary-result-option", + function() { + $.post( + ajaxurl, + { + action: "sp-save-primary-result", + primary_result: $( this ).val(), + nonce: $( "#sp-primary-result-nonce" ).val() + } + ); + } + ); + + // Configure primary performance option (Ajax) + $( ".sp-admin-config-table" ).on( + "click", + ".sp-primary-performance-option", + function() { + $.post( + ajaxurl, + { + action: "sp-save-primary-performance", + primary_performance: $( this ).val(), + nonce: $( "#sp-primary-performance-nonce" ).val() + } + ); + } + ); + + // Update importer post count + $( ".sp-import-table" ).on( + "updatePostCount", + function() { + $( ".sp-post-count" ).text( localized_strings.displaying_posts.replace( "%s", 1 ).replace( /%s/g, count = $( this ).find( "tbody tr" ).length ) ); + } + ); + + // Delete importer row + $( ".sp-import-table" ).on( + "click", + ".sp-delete-row", + function() { + $self = $( this ); + $self.closest( "tr" ).css( "background-color", "#f99" ).fadeOut( + 400, + function() { + $table = $self.closest( ".sp-import-table" ); + $( this ).remove(); + $table.trigger( "updatePostCount" ); + } + ); + return false; + } + ); + + // Add importer row + $( ".sp-import-table" ).on( + "click", + ".sp-add-row", + function() { + $self = $( this ); + $table = $self.closest( ".sp-import-table" ); + if ( $self.hasClass( "sp-add-first" ) ) { + $tr = $table.find( "tbody tr:first-child" ); + $row = $tr.clone(); + $row.insertBefore( $tr ).find( "input" ).val( "" ); + } else { + $tr = $self.closest( "tr" ); + $row = $tr.clone(); + $tr.find( "input" ).val( "" ); + $row.insertBefore( $tr ); + } + $table.trigger( "updatePostCount" ); + return false; + } + ); + + // Enable or disable importer inputs based on column label + $( ".sp-import-table" ).on( + "change", + "select", + function() { + $self = $( this ); + $table = $self.closest( ".sp-import-table" ); + index = parseInt( $self.data( "index" ) ); + if ( $self.val() == 0 ) { + $table.find( "tbody tr td:nth-child(" + parseInt( index + 1 ) + ") input" ).prop( "disabled", true ); + } else { + $table.find( "tbody tr td:nth-child(" + parseInt( index + 1 ) + ") input" ).prop( "disabled", false ); + $self.closest( "th" ).siblings().find( "select" ).each( + function() { + if ( $( this ).val() == $self.val() ) { + $( this ).val( "0" ).trigger( "change" ); + } + } + ); + } + } + ); + + // Datepicker + $( ".sp-datepicker" ).datepicker( + { + dateFormat : "yy-mm-dd" + } + ); + $( ".sp-datepicker-from" ).datepicker( + { + dateFormat : "yy-mm-dd", + onClose: function( selectedDate ) { + $( this ).closest( ".sp-date-selector" ).find( ".sp-datepicker-to" ).datepicker( "option", "minDate", selectedDate ); + } + } + ); + $( ".sp-datepicker-to" ).datepicker( + { + dateFormat : "yy-mm-dd", + onClose: function( selectedDate ) { + $( this ).closest( ".sp-date-selector" ).find( ".sp-datepicker-from" ).datepicker( "option", "maxDate", selectedDate ); + } + } + ); + + // Show or hide datepicker + $( ".sp-date-selector select" ).change( + function() { + if ( $( this ).val() == "range" ) { + $( this ).closest( ".sp-date-selector" ).find( ".sp-date-range" ).show(); + } else { + $( this ).closest( ".sp-date-selector" ).find( ".sp-date-range" ).hide(); + } + } + ); + $( ".sp-date-selector select" ).trigger( "change" ); + + // Toggle date range selectors + $( ".sp-date-relative input" ).change( + function() { + $relative = $( this ).closest( ".sp-date-relative" ).siblings( ".sp-date-range-relative" ).toggle( 0, $( this ).attr( "checked" ) ); + $absolute = $( this ).closest( ".sp-date-relative" ).siblings( ".sp-date-range-absolute" ).toggle( 0, $( this ).attr( "checked" ) ); + + if ($( this ).attr( "checked" )) { + $relative.show(); + $absolute.hide(); + } else { + $absolute.show(); + $relative.hide(); + } + } + ); + $( ".sp-date-selector input" ).trigger( "change" ); + + // Apply color scheme + $( ".sp-color-option" ).on( + "click", + function() { + colors = $( this ).find( "label" ).data( "sp-colors" ).split( "," ); + $( ".sp-custom-colors" ).find( ".sp-color-box" ).each( + function(index) { + $( this ).find( "input" ).val( "#" + colors[index] ).css( "background-color", "#" + colors[index] ); + } + );; + } + ); + + // Edit inline results + $( "#the-list" ).on( + "click, focus", + ".sp-result, .sp-edit-results", + function(){ + team = $( this ).data( "team" ); + $column = $( this ).closest( ".column-sp_team" ); + $column.find( ".sp-result, .sp-row-actions" ).hide(); + $column.find( ".sp-edit-result, .sp-inline-edit-save" ).show(); + if ( team != undefined ) { + $column.find( ".sp-edit-result[data-team='" + team + "']" ).select(); + } + return false; + } + ); + + // Cancel inline results + $( "#the-list" ).on( + "click", + ".sp-inline-edit-save .cancel", + function(){ + $column = $( this ).closest( ".column-sp_team" ); + $column.find( ".sp-edit-result, .sp-inline-edit-save" ).hide(); + $column.find( ".sp-result, .sp-row-actions" ).show(); + return false; + } + ); + + // Save inline results + $( "#the-list" ).on( + "click", + ".sp-inline-edit-save .save", + function(){ + $column = $( this ).closest( ".column-sp_team" ); + results = {}; + $column.find( ".sp-edit-result" ).each( + function() { + id = $( this ).data( "team" ); + result = $( this ).val(); + results[id] = result; + } + ); + $.post( + ajaxurl, + { + action: "sp-save-inline-results", + post_id: $column.find( "input[name='sp_post_id']" ).val(), + results: results, + nonce: $( "#sp-inline-nonce" ).val() + }, + function(response) { + $column.find( ".sp-edit-result" ).each( + function() { + val = $( this ).val(); + $column.find( ".sp-result[data-team='" + $( this ).data( "team" ) + "']" ).html( val == '' ? '-' : val ); + } + ); + $column.find( ".sp-edit-result, .sp-inline-edit-save" ).hide(); + $column.find( ".sp-result, .sp-row-actions" ).show(); + return false; + } + ); + } + ); + + // Override inline form submission + $( "#the-list" ).on( + "keypress", + ".sp-edit-result", + function(e) { + if ( e.which == 13 ) { + $( this ).closest( ".column-sp_team" ).find( ".sp-inline-edit-save .save" ).trigger( "click" ); + return false; + } + } + ); + + // Fitvids + $( ".sp-fitvids" ).fitVids(); + + // Display configure sport button + $( ".sp-select-sport" ).change( + function() { + $( ".sp-configure-sport" ).hide(); + } + ); + + // Ajax checklist + $( ".sp-ajax-checklist" ).siblings( ".sp-tab-select" ).find( "select" ).change( + function() { + $( this ).closest( ".sp-tab-select" ).siblings( ".sp-ajax-checklist" ).find( "ul" ).html( "
  • " + localized_strings.loading + "
  • " ); + $.post( + ajaxurl, + { + action: "sp-get-players", + team: $( this ).val(), + league: ('yes' == localized_strings.option_filter_by_league) ? $( "select[name=\"tax_input[sp_league][]\"]" ).val() : null, + season: ('yes' == localized_strings.option_filter_by_season) ? $( "select[name=\"tax_input[sp_season][]\"]" ).val() : null, + index: $( this ).closest( ".sp-instance" ).index(), + nonce: $( "#sp-get-players-nonce" ).val() + } + ).done( + function( response ) { + index = response.data.index; + $target = $( ".sp-instance" ).eq( index ).find( ".sp-ajax-checklist ul" ); + if ( response.success ) { + $target.html( "" ); + i = 0; + if (-1 == response.data.sections) { + if (response.data.players.length) { + $target.eq( 0 ).append( "
  • " ); + $( response.data.players ).each( + function( key, value ) { + $target.eq( 0 ).append( "
  • " ); + } + ); + $target.eq( 0 ).append( "
  • " + localized_strings.show_all + "
  • " ); + } else { + $target.eq( 0 ).html( "
  • " + localized_strings.no_results_found + " " + localized_strings.show_all + "
  • " ); + } + } else { + if ( 1 == response.data.sections ) { + defense = i; + offense = i + 1; + } else { + offense = i; + defense = i + 1; + } + if (response.data.players.length) { + $target.eq( offense ).append( "
  • " ); + $target.eq( defense ).append( "
  • " ); + $( response.data.players ).each( + function( key, value ) { + $target.eq( offense ).append( "
  • " ); + $target.eq( defense ).append( "
  • " ); + } + ); + $target.eq( offense ).append( "
  • " + localized_strings.show_all + "
  • " ); + $target.eq( defense ).append( "
  • " + localized_strings.show_all + "
  • " ); + } else { + $target.eq( offense ).html( "
  • " + localized_strings.no_results_found + " " + localized_strings.show_all + "
  • " ); + $target.eq( defense ).html( "
  • " + localized_strings.no_results_found + " " + localized_strings.show_all + "
  • " ); + } + i++; + } + i++; + if (response.data.staff.length) { + $target.eq( i ).append( "
  • " ); + $( response.data.staff ).each( + function( key, value ) { + $target.eq( i ).append( "
  • " ); + } + ); + $target.eq( i ).append( "
  • " + localized_strings.show_all + "
  • " ); + } else { + $target.eq( i ).html( "
  • " + localized_strings.no_results_found + " " + localized_strings.show_all + "
  • " ); + } + } else { + $target.html( "
  • " + localized_strings.no_results_found + "
  • " ); + } + } + ); + } + ); + + // Activate Ajax trigger + $( ".sp-ajax-trigger" ).change( + function() { + $( ".sp-ajax-checklist" ).siblings( ".sp-tab-select" ).find( "select" ).change(); + } + ); + + // Ajax show all filter + $( ".sp-tab-panel" ).on( + "click", + ".sp-ajax-show-all", + function() { + index = $( this ).closest( ".sp-instance" ).index(); + $( this ).parent().html( localized_strings.loading ); + $.post( + ajaxurl, + { + action: "sp-get-players", + index: index, + nonce: $( "#sp-get-players-nonce" ).val() + } + ).done( + function( response ) { + index = response.data.index; + console.log( index ); + $target = $( ".sp-instance" ).eq( index ).find( ".sp-ajax-checklist ul" ); + $target.find( ".sp-ajax-show-all-container" ).hide(); + if ( response.success ) { + i = 0; + console.log( response.data.sections ); + if ( -1 == response.data.sections ) { + if (response.data.players.length) { + $( response.data.players ).each( + function( key, value ) { + if ($target.eq( i ).find( "input[value=" + value.ID + "]" ).length) { + return true; + } + $target.eq( i ).append( "
  • " ); + } + ); + } else { + $target.eq( i ).html( "
  • " + localized_strings.no_results_found + "
  • " ); + } + } else { + if (response.data.players.length) { + if ( 1 == response.data.sections ) { + defense = i; + offense = i + 1; + } else { + offense = i; + defense = i + 1; + } + $( response.data.players ).each( + function( key, value ) { + $target.eq( offense ).append( "
  • " ); + $target.eq( defense ).append( "
  • " ); + } + ); + } else { + $target.eq( offense ).html( "
  • " + localized_strings.no_results_found + "
  • " ); + $target.eq( defense ).html( "
  • " + localized_strings.no_results_found + "
  • " ); + } + i++; + } + i++; + if (response.data.staff.length) { + $( response.data.staff ).each( + function( key, value ) { + $target.eq( i ).append( "
  • " ); + } + ); + } else { + $target.eq( i ).html( "
  • " + localized_strings.no_results_found + "
  • " ); + } + } else { + $target.html( "
  • " + localized_strings.no_results_found + "
  • " ); + } + } + ); + } + ); + + // Event status selector + $( '.sp-edit-event-status' ).click( + function(e) { + e.preventDefault(); + $select = $( this ).siblings( '.sp-event-status-select' ); + if ( $select.is( ':hidden' ) ) { + $select.slideDown( + 'fast', + function() { + $select.find( 'input[type="radio"]' ).first().focus(); + } + ); + $( this ).hide(); + } + } + ); + + $( '.sp-save-event-status' ).click( + function(e) { + e.preventDefault(); + $select = $( this ).closest( '.sp-event-status-select' ); + $input = $select.find( 'input[name=sp_status]:checked' ); + val = $input.val(); + label = $input.data( 'sp-event-status' ); + $select.slideUp( 'fast' ).siblings( '.sp-edit-event-status' ).show().siblings( '.sp-event-status' ).find( '.sp-event-status-display' ).data( 'sp-event-status', val ).html( label ); + } + ); + + $( '.sp-cancel-event-status' ).click( + function(e) { + e.preventDefault(); + $select = $( this ).closest( '.sp-event-status-select' ); + val = $select.siblings( '.sp-event-status' ).find( '.sp-event-status-display' ).data( 'sp-event-status' ); + $select.find( 'input[value=' + val + ']' ).attr( 'checked', true ); + $select.slideUp( 'fast' ).siblings( '.sp-edit-event-status' ).show(); + } + ); + + // Box score time converter + $( '.sp-convert-time-input' ).change( + function() { + var s = 0; + var val = $( this ).val(); + if (val === '') { + $( this ).siblings( '.sp-convert-time-output' ).val( '' ); + return; + } + var a = val.split( ':' ).reverse(); + $.each( + a, + function( index, value ) { + s += parseInt( value ) * Math.pow( 60, index ); + } + ); + $( this ).siblings( '.sp-convert-time-output' ).val( s ); + } + ); + + // Trigger box score time converter + $( '.sp-convert-time-input' ).change(); + + // Trigger show/hide of team table ordering + $( '#sp_orderby' ).change( + function(){ + if ($( '#sp_orderby' ).val() == 'default') { + $( "#sp_order" ).hide(); + } else { + $( '#sp_order' ).show(); + } + } + ); + } +); diff --git a/assets/js/admin/sportspress-setup.js b/assets/js/admin/sportspress-setup.js index 74573e3d..7f5e8308 100644 --- a/assets/js/admin/sportspress-setup.js +++ b/assets/js/admin/sportspress-setup.js @@ -1,24 +1,32 @@ -jQuery(document).ready(function($){ +jQuery( document ).ready( + function($){ - // Tiptip - $(".sp-tip").tipTip({ - delay: 200, - fadeIn: 100, - fadeOut: 100 - }); - $(".sp-desc-tip").tipTip({ - delay: 200, - fadeIn: 100, - fadeOut: 100, - defaultPosition: 'right' - }); + // Tiptip + $( ".sp-tip" ).tipTip( + { + delay: 200, + fadeIn: 100, + fadeOut: 100 + } + ); + $( ".sp-desc-tip" ).tipTip( + { + delay: 200, + fadeIn: 100, + fadeOut: 100, + defaultPosition: 'right' + } + ); - // Chosen select - $(".chosen-select, #poststuff #post_author_override").chosen({ - allow_single_deselect: true, - search_contains: true, - single_backstroke_delete: false, - disable_search_threshold: 10, - placeholder_text_multiple: localized_strings.none - }); -}); \ No newline at end of file + // Chosen select + $( ".chosen-select, #poststuff #post_author_override" ).chosen( + { + allow_single_deselect: true, + search_contains: true, + single_backstroke_delete: false, + disable_search_threshold: 10, + placeholder_text_multiple: localized_strings.none + } + ); + } +); diff --git a/assets/js/admin/widgets.js b/assets/js/admin/widgets.js index 0aba986d..057dd5df 100644 --- a/assets/js/admin/widgets.js +++ b/assets/js/admin/widgets.js @@ -1,41 +1,60 @@ -jQuery(document).ready(function($){ +jQuery( document ).ready( + function($){ - // Orderby affects order select in widget options - $("body").on("change", ".sp-select-orderby", function() { - $(this).closest(".widget-content").find(".sp-select-order").prop("disabled", $(this).val() == "default"); - }); + // Orderby affects order select in widget options + $( "body" ).on( + "change", + ".sp-select-orderby", + function() { + $( this ).closest( ".widget-content" ).find( ".sp-select-order" ).prop( "disabled", $( this ).val() == "default" ); + } + ); - // Calendar affects view all link checkbox in widget options - $("body").on("change", ".sp-event-calendar-select", function() { - $el = $(this).closest(".widget-content").find(".sp-event-calendar-show-all-toggle"); - if($(this).val() == 0) - $el.hide(); - else - $el.show(); - }); + // Calendar affects view all link checkbox in widget options + $( "body" ).on( + "change", + ".sp-event-calendar-select", + function() { + $el = $( this ).closest( ".widget-content" ).find( ".sp-event-calendar-show-all-toggle" ); + if ($( this ).val() == 0) { + $el.hide(); + } else { + $el.show(); + } + } + ); - // Show or hide datepicker - $("body").on("change", ".sp-date-selector select", function() { - if ( $(this).val() == "range" ) { - $(this).closest(".sp-date-selector").find(".sp-date-range").show(); - } else { - $(this).closest(".sp-date-selector").find(".sp-date-range").hide(); - } - }); - $(".sp-date-selector select").trigger("change"); + // Show or hide datepicker + $( "body" ).on( + "change", + ".sp-date-selector select", + function() { + if ( $( this ).val() == "range" ) { + $( this ).closest( ".sp-date-selector" ).find( ".sp-date-range" ).show(); + } else { + $( this ).closest( ".sp-date-selector" ).find( ".sp-date-range" ).hide(); + } + } + ); + $( ".sp-date-selector select" ).trigger( "change" ); - // Toggle date range selectors - $("body").on("change", ".sp-date-relative input", function() { - $relative = $(this).closest(".sp-date-relative").siblings(".sp-date-range-relative").toggle(0, $(this).attr("checked")); - $absolute = $(this).closest(".sp-date-relative").siblings(".sp-date-range-absolute").toggle(0, $(this).attr("checked")); + // Toggle date range selectors + $( "body" ).on( + "change", + ".sp-date-relative input", + function() { + $relative = $( this ).closest( ".sp-date-relative" ).siblings( ".sp-date-range-relative" ).toggle( 0, $( this ).attr( "checked" ) ); + $absolute = $( this ).closest( ".sp-date-relative" ).siblings( ".sp-date-range-absolute" ).toggle( 0, $( this ).attr( "checked" ) ); - if ($(this).attr("checked")) { - $relative.show(); - $absolute.hide(); - } else { - $absolute.show(); - $relative.hide(); - } - }); - $(".sp-date-selector input").trigger("change"); -}); \ No newline at end of file + if ($( this ).attr( "checked" )) { + $relative.show(); + $absolute.hide(); + } else { + $absolute.show(); + $relative.hide(); + } + } + ); + $( ".sp-date-selector input" ).trigger( "change" ); + } +); diff --git a/assets/js/blocks/event-calendar.js b/assets/js/blocks/event-calendar.js index 7b749b00..8a0adde5 100644 --- a/assets/js/blocks/event-calendar.js +++ b/assets/js/blocks/event-calendar.js @@ -1,81 +1,88 @@ import apiFetch from '@wordpress/api-fetch'; -console.log(wp.api.collections.Posts()); +console.log( wp.api.collections.Posts() ); -wp.blocks.registerBlockType('sportspress/event-calendar', { - title: strings.event_calendar, - icon: 'calendar', - category: 'sportspress', - attributes: { - title: { - type: 'string' - }, - id: { - type: 'number' - }, - status: { - type: 'string' - }, - date: { - type: 'string' - }, - date_from: { - type: 'string' - }, - date_to: { - type: 'string' - }, - date_past: { - type: 'number' - }, - date_future: { - type: 'number' - }, - date_relative: { - type: 'number' - }, - day: { - type: 'string' - }, - show_all_events_link: { - type: 'number' - }, +wp.blocks.registerBlockType( + 'sportspress/event-calendar', + { + title: strings.event_calendar, + icon: 'calendar', + category: 'sportspress', + attributes: { + title: { + type: 'string' + }, + id: { + type: 'number' + }, + status: { + type: 'string' + }, + date: { + type: 'string' + }, + date_from: { + type: 'string' + }, + date_to: { + type: 'string' + }, + date_past: { + type: 'number' + }, + date_future: { + type: 'number' + }, + date_relative: { + type: 'number' + }, + day: { + type: 'string' + }, + show_all_events_link: { + type: 'number' + }, - content: {type: 'string'}, - color: {type: 'string'} - }, - - edit: function(props) { - function updateContent(event) { - props.setAttributes({content: event.target.value}) - } - function updateColor(value) { - props.setAttributes({color: value.hex}) - } - return React.createElement( - wp.components.Panel, - {header: strings.event_calendar}, - React.createElement( - wp.components.PanelBody, - {title: strings.properties}, - React.createElement( - wp.components.TextControl, - {label: strings.title, type: "text", value: props.attributes.title} - ), - React.createElement( - wp.components.SelectControl, - {label: strings.select_calendar, options: [{label: strings.all, value: 0}].concat(posts.events.map(post => { - return {label: post.post_title, value: post.ID} - }))} - ) - ) - ); - }, + content: {type: 'string'}, + color: {type: 'string'} + }, - save: function(props) { - return wp.element.createElement( - "h3", - { style: { border: "3px solid " + props.attributes.color } }, - props.attributes.content - ); - } -}) \ No newline at end of file + edit: function(props) { + function updateContent(event) { + props.setAttributes( {content: event.target.value} ) + } + function updateColor(value) { + props.setAttributes( {color: value.hex} ) + } + return React.createElement( + wp.components.Panel, + {header: strings.event_calendar}, + React.createElement( + wp.components.PanelBody, + {title: strings.properties}, + React.createElement( + wp.components.TextControl, + {label: strings.title, type: "text", value: props.attributes.title} + ), + React.createElement( + wp.components.SelectControl, + {label: strings.select_calendar, options: [{label: strings.all, value: 0}].concat( + posts.events.map( + post => { + return {label: post.post_title, value: post.ID} + } + ) + )} + ) + ) + ); + }, + + save: function(props) { + return wp.element.createElement( + "h3", + { style: { border: "3px solid " + props.attributes.color } }, + props.attributes.content + ); + } + } +) diff --git a/assets/js/jquery.fitvids.js b/assets/js/jquery.fitvids.js index 231d3b5d..d81533ae 100644 --- a/assets/js/jquery.fitvids.js +++ b/assets/js/jquery.fitvids.js @@ -11,73 +11,77 @@ (function( $ ){ - 'use strict'; + 'use strict'; - $.fn.fitVids = function( options ) { - var settings = { - customSelector: null, - ignore: null - }; + $.fn.fitVids = function( options ) { + var settings = { + customSelector: null, + ignore: null + }; - if(!document.getElementById('fit-vids-style')) { - // appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js - var head = document.head || document.getElementsByTagName('head')[0]; - var css = '.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}'; - var div = document.createElement("div"); - div.innerHTML = '

    x

    '; - head.appendChild(div.childNodes[1]); - } + if ( ! document.getElementById( 'fit-vids-style' )) { + // appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js + var head = document.head || document.getElementsByTagName( 'head' )[0]; + var css = '.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}'; + var div = document.createElement( "div" ); + div.innerHTML = '

    x

    '; + head.appendChild( div.childNodes[1] ); + } - if ( options ) { - $.extend( settings, options ); - } + if ( options ) { + $.extend( settings, options ); + } - return this.each(function(){ - var selectors = [ - 'iframe[src*="player.vimeo.com"]', - 'iframe[src*="youtube.com"]', - 'iframe[src*="youtube-nocookie.com"]', - 'iframe[src*="kickstarter.com"][src*="video.html"]', - 'object', - 'embed' - ]; + return this.each( + function(){ + var selectors = [ + 'iframe[src*="player.vimeo.com"]', + 'iframe[src*="youtube.com"]', + 'iframe[src*="youtube-nocookie.com"]', + 'iframe[src*="kickstarter.com"][src*="video.html"]', + 'object', + 'embed' + ]; - if (settings.customSelector) { - selectors.push(settings.customSelector); - } + if (settings.customSelector) { + selectors.push( settings.customSelector ); + } - var ignoreList = '.fitvidsignore'; + var ignoreList = '.fitvidsignore'; - if(settings.ignore) { - ignoreList = ignoreList + ', ' + settings.ignore; - } + if (settings.ignore) { + ignoreList = ignoreList + ', ' + settings.ignore; + } - var $allVideos = $(this).find(selectors.join(',')); - $allVideos = $allVideos.not('object object'); // SwfObj conflict patch - $allVideos = $allVideos.not(ignoreList); // Disable FitVids on this video. + var $allVideos = $( this ).find( selectors.join( ',' ) ); + $allVideos = $allVideos.not( 'object object' ); // SwfObj conflict patch + $allVideos = $allVideos.not( ignoreList ); // Disable FitVids on this video. - $allVideos.each(function(){ - var $this = $(this); - if($this.parents(ignoreList).length > 0) { - return; // Disable FitVids on this video. - } - if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; } - if ((!$this.css('height') && !$this.css('width')) && (isNaN($this.attr('height')) || isNaN($this.attr('width')))) - { - $this.attr('height', 9); - $this.attr('width', 16); - } - var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(), - width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(), - aspectRatio = height / width; - if(!$this.attr('id')){ - var videoID = 'fitvid' + Math.floor(Math.random()*999999); - $this.attr('id', videoID); - } - $this.wrap('
    ').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+'%'); - $this.removeAttr('height').removeAttr('width'); - }); - }); - }; -// Works with either jQuery or Zepto + $allVideos.each( + function(){ + var $this = $( this ); + if ($this.parents( ignoreList ).length > 0) { + return; // Disable FitVids on this video. + } + if (this.tagName.toLowerCase() === 'embed' && $this.parent( 'object' ).length || $this.parent( '.fluid-width-video-wrapper' ).length) { + return; } + if (( ! $this.css( 'height' ) && ! $this.css( 'width' )) && (isNaN( $this.attr( 'height' ) ) || isNaN( $this.attr( 'width' ) ))) { + $this.attr( 'height', 9 ); + $this.attr( 'width', 16 ); + } + var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr( 'height' ) && ! isNaN( parseInt( $this.attr( 'height' ), 10 ) )) ) ? parseInt( $this.attr( 'height' ), 10 ) : $this.height(), + width = ! isNaN( parseInt( $this.attr( 'width' ), 10 ) ) ? parseInt( $this.attr( 'width' ), 10 ) : $this.width(), + aspectRatio = height / width; + if ( ! $this.attr( 'id' )) { + var videoID = 'fitvid' + Math.floor( Math.random() * 999999 ); + $this.attr( 'id', videoID ); + } + $this.wrap( '
    ' ).parent( '.fluid-width-video-wrapper' ).css( 'padding-top', (aspectRatio * 100) + '%' ); + $this.removeAttr( 'height' ).removeAttr( 'width' ); + } + ); + } + ); + }; + // Works with either jQuery or Zepto })( window.jQuery || window.Zepto ); diff --git a/assets/js/sportspress.js b/assets/js/sportspress.js index 09ef3fb1..cfedf4d8 100644 --- a/assets/js/sportspress.js +++ b/assets/js/sportspress.js @@ -1,119 +1,138 @@ function sp_viewport() { - var e = window, a = 'inner'; - if (!('innerWidth' in window )) { - a = 'client'; - e = document.documentElement || document.body; - } - return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }; + var e = window, a = 'inner'; + if ( ! ('innerWidth' in window )) { + a = 'client'; + e = document.documentElement || document.body; + } + return { width : e[ a + 'Width' ] , height : e[ a + 'Height' ] }; } (function($) { /* Header */ - if ( ! $('.sp-header').length ) { - $('body').prepend( '
    ' ); + if ( ! $( '.sp-header' ).length ) { + $( 'body' ).prepend( '
    ' ); } /* Countdown */ - $("[data-countdown]").each(function() { - var $this = $(this); - // Get countdown time - var countDownDate = new Date($(this).data('countdown')).getTime(); - // Iterate every second - var x = setInterval(function() { - - // Get todays date and time - var now = new Date(); - - // Convert curent date and time to UTC - var tzDifference = now.getTimezoneOffset(); - var nowutc = new Date(now.getTime() + tzDifference * 60 * 1000); - - // Find the distance between now and the count down date - var distance = countDownDate - nowutc; - if ( distance < 0 ) { - distance = 0; - } - - // Time calculations for days, hours, minutes and seconds - var days = Math.floor(distance / (1000 * 60 * 60 * 24)); - var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); - var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); - var seconds = Math.floor((distance % (1000 * 60)) / 1000); - - // Output the result - $this.html(""+(days < 10 ? '0' + days : days)+" " + localized_strings.days + " " - + ""+('0' + hours).slice(-2)+" " + localized_strings.hrs + " " - + ""+('0' + minutes).slice(-2)+" " + localized_strings.mins + " " - + ""+('0' + seconds).slice(-2)+" " + localized_strings.secs + "" ); - }, 1000); - }); + $( "[data-countdown]" ).each( + function() { + var $this = $( this ); + // Get countdown time + var countDownDate = new Date( $( this ).data( 'countdown' ) ).getTime(); + // Iterate every second + var x = setInterval( + function() { + + // Get todays date and time + var now = new Date(); + + // Convert curent date and time to UTC + var tzDifference = now.getTimezoneOffset(); + var nowutc = new Date( now.getTime() + tzDifference * 60 * 1000 ); + + // Find the distance between now and the count down date + var distance = countDownDate - nowutc; + if ( distance < 0 ) { + distance = 0; + } + + // Time calculations for days, hours, minutes and seconds + var days = Math.floor( distance / (1000 * 60 * 60 * 24) ); + var hours = Math.floor( (distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60) ); + var minutes = Math.floor( (distance % (1000 * 60 * 60)) / (1000 * 60) ); + var seconds = Math.floor( (distance % (1000 * 60)) / 1000 ); + + // Output the result + $this.html( + "" + (days < 10 ? '0' + days : days) + " " + localized_strings.days + " " + + "" + ('0' + hours).slice( -2 ) + " " + localized_strings.hrs + " " + + "" + ('0' + minutes).slice( -2 ) + " " + localized_strings.mins + " " + + "" + ('0' + seconds).slice( -2 ) + " " + localized_strings.secs + "" + ); + }, + 1000 + ); + } + ); /* Scrollable Tables */ - $(".sp-scrollable-table").wrap("
    "); - + $( ".sp-scrollable-table" ).wrap( "
    " ); + /* Selector Redirect */ - $(".sp-selector-redirect").change(function() { - window.location = $(this).val(); - }); + $( ".sp-selector-redirect" ).change( + function() { + window.location = $( this ).val(); + } + ); /* Template Tabs */ - $(".sp-tab-menu-item a").click(function() { - $template = $(this).data("sp-tab"); - $(this).closest(".sp-tab-menu-item").addClass("sp-tab-menu-item-active").siblings(".sp-tab-menu-item").removeClass("sp-tab-menu-item-active"); - $(this).closest(".sp-tab-group").find(".sp-tab-content-"+$template).show().siblings(".sp-tab-content").hide(); - return false; - }); + $( ".sp-tab-menu-item a" ).click( + function() { + $template = $( this ).data( "sp-tab" ); + $( this ).closest( ".sp-tab-menu-item" ).addClass( "sp-tab-menu-item-active" ).siblings( ".sp-tab-menu-item" ).removeClass( "sp-tab-menu-item-active" ); + $( this ).closest( ".sp-tab-group" ).find( ".sp-tab-content-" + $template ).show().siblings( ".sp-tab-content" ).hide(); + return false; + } + ); /* API method to get paging information */ $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings ) { - return { - "iStart": oSettings._iDisplayStart, - "iEnd": oSettings.fnDisplayEnd(), - "iLength": oSettings._iDisplayLength, - "iTotal": oSettings.fnRecordsTotal(), - "iFilteredTotal": oSettings.fnRecordsDisplay(), - "iPage": oSettings._iDisplayLength === -1 ? - 0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ), - "iTotalPages": oSettings._iDisplayLength === -1 ? - 0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength ) - }; + return { + "iStart": oSettings._iDisplayStart, + "iEnd": oSettings.fnDisplayEnd(), + "iLength": oSettings._iDisplayLength, + "iTotal": oSettings.fnRecordsTotal(), + "iFilteredTotal": oSettings.fnRecordsDisplay(), + "iPage": oSettings._iDisplayLength === -1 ? + 0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ), + "iTotalPages": oSettings._iDisplayLength === -1 ? + 0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength ) + }; } /* Data Tables */ - $(".sp-data-table").each(function() { - sortable = $(this).hasClass("sp-sortable-table"); - paginated = $(this).hasClass("sp-paginated-table"); - display_length = parseInt($(this).attr("data-sp-rows")); - if ( display_length == undefined || isNaN( display_length ) ) display_length = 10; - if ( $(this).find("tbody tr").length <= display_length ) paginated = false; - if ( sortable || paginated ) { - $(this).dataTable({ - "order": [], - "autoWidth": false, - "searching": false, - "info": false, - "paging": paginated, - "lengthChange": false, - "pagingType": "simple_numbers", - "pageLength": display_length, - "ordering": sortable, - "language": { - "aria": { - "sortAscending": "", - "sortDescending": "" - }, - "paginate": { - "previous": localized_strings.previous, - "next": localized_strings.next, - } - }, - "columnDefs": [ - { "type": "num-fmt", "targets": [ ".data-number", ".data-rank" ] }, - ] - }); + $( ".sp-data-table" ).each( + function() { + sortable = $( this ).hasClass( "sp-sortable-table" ); + paginated = $( this ).hasClass( "sp-paginated-table" ); + display_length = parseInt( $( this ).attr( "data-sp-rows" ) ); + if ( display_length == undefined || isNaN( display_length ) ) { + display_length = 10; + } + if ( $( this ).find( "tbody tr" ).length <= display_length ) { + paginated = false; + } + if ( sortable || paginated ) { + $( this ).dataTable( + { + "order": [], + "autoWidth": false, + "searching": false, + "info": false, + "paging": paginated, + "lengthChange": false, + "pagingType": "simple_numbers", + "pageLength": display_length, + "ordering": sortable, + "language": { + "aria": { + "sortAscending": "", + "sortDescending": "" + }, + "paginate": { + "previous": localized_strings.previous, + "next": localized_strings.next, + } + }, + "columnDefs": [ + { "type": "num-fmt", "targets": [ ".data-number", ".data-rank" ] }, + ] + } + ); + } } - }); + ); -})(jQuery); +})( jQuery ); diff --git a/feeds/ical.php b/feeds/ical.php index 768bd46b..f2e2a1e2 100644 --- a/feeds/ical.php +++ b/feeds/ical.php @@ -2,13 +2,15 @@ /** * iCal Feed * - * @author ThemeBoy - * @category Feeds - * @package SportsPress/Feeds + * @author ThemeBoy + * @category Feeds + * @package SportsPress/Feeds * @version 2.7.5 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( 'sp_calendar' !== get_post_type( $post ) ) { wp_die( __( 'ERROR: This is not a valid feed template.', 'sportspress' ), '', array( 'response' => 404 ) ); @@ -16,7 +18,7 @@ if ( 'sp_calendar' !== get_post_type( $post ) ) { // Get events in calendar $calendar = new SP_Calendar( $post ); -$events = $calendar->data(); +$events = $calendar->data(); // Get blog locale $locale = substr( get_locale(), 0, 2 ); @@ -29,41 +31,43 @@ $timezone = sanitize_option( 'timezone_string', get_option( 'timezone_string' ) // Get the URL $url = add_query_arg( 'feed', 'sp-ical', get_post_permalink( $post ) ); -$url = wordwrap( $url , 60, "\r\n\t", true ); +$url = wordwrap( $url, 60, "\r\n\t", true ); $output = "BEGIN:VCALENDAR\r\n" . "VERSION:2.0\r\n" . -"PRODID:-//ThemeBoy//SportsPress//" . strtoupper( $locale ) . "\r\n" . +'PRODID:-//ThemeBoy//SportsPress//' . strtoupper( $locale ) . "\r\n" . "CALSCALE:GREGORIAN\r\n" . "METHOD:PUBLISH\r\n" . -"URL:" . $url . "\r\n" . -"X-FROM-URL:" . $url . "\r\n" . -"NAME:" . $post->post_title . "\r\n" . -"X-WR-CALNAME:" . $post->post_title . "\r\n" . -"DESCRIPTION:" . $post->post_title . "\r\n" . -"X-WR-CALDESC:" . $post->post_title . "\r\n" . +'URL:' . $url . "\r\n" . +'X-FROM-URL:' . $url . "\r\n" . +'NAME:' . $post->post_title . "\r\n" . +'X-WR-CALNAME:' . $post->post_title . "\r\n" . +'DESCRIPTION:' . $post->post_title . "\r\n" . +'X-WR-CALDESC:' . $post->post_title . "\r\n" . "REFRESH-INTERVAL;VALUE=DURATION:PT2M\r\n" . "X-PUBLISHED-TTL:PT2M\r\n" . -"TZID:" . $timezone . "\r\n" . -"X-WR-TIMEZONE:" . $timezone . "\r\n"; +'TZID:' . $timezone . "\r\n" . +'X-WR-TIMEZONE:' . $timezone . "\r\n"; // Loop through each event -foreach ( $events as $event): +foreach ( $events as $event ) : // Define date format $date_format = 'Ymd\THis'; // Get description - $description = preg_replace( '/([\,;])/','\\\$1', $event->post_content ); - $description = wordwrap( $description , 60, "\n\t" ); + $description = preg_replace( '/([\,;])/', '\\\$1', $event->post_content ); + $description = wordwrap( $description, 60, "\n\t" ); - // Initialize end time + // Initialize end time $end = new DateTime( $event->post_date ); // Get full time minutes $minutes = get_post_meta( $event->ID, 'sp_minutes', true ); - if ( '' === $minutes ) $minutes = get_option( 'sportspress_event_minutes', 90 ); + if ( '' === $minutes ) { + $minutes = get_option( 'sportspress_event_minutes', 90 ); + } // Add full time minutes to end time $end->add( new DateInterval( 'PT' . $minutes . 'M' ) ); @@ -74,7 +78,7 @@ foreach ( $events as $event): // Get venue information $venues = get_the_terms( $event->ID, 'sp_venue' ); if ( $venues ) { - $venue = reset( $venues ); + $venue = reset( $venues ); $location .= $venue->name; // Get venue term meta @@ -84,11 +88,11 @@ foreach ( $events as $event): // Add details to location $address = sp_array_value( $meta, 'sp_address', false ); if ( false !== $address ) { - $location = $venue->name . '\, ' . preg_replace('/([\,;])/','\\\$1', $address); + $location = $venue->name . '\, ' . preg_replace( '/([\,;])/', '\\\$1', $address ); } // Generate geo tag - $latitude = sp_array_value( $meta, 'sp_latitude', false ); + $latitude = sp_array_value( $meta, 'sp_latitude', false ); $longitude = sp_array_value( $meta, 'sp_longitude', false ); if ( false !== $latitude && false !== $longitude ) { $geo = $latitude . ';' . $longitude; @@ -96,17 +100,19 @@ foreach ( $events as $event): $geo = false; } } - $location = wordwrap( $location , 60, "\r\n\t" ); + $location = wordwrap( $location, 60, "\r\n\t" ); // Get title or write summary based on scores $results = array(); - $teams = (array)get_post_meta( $event->ID, 'sp_team', false ); - $teams = array_filter( $teams ); - $teams = array_unique( $teams ); + $teams = (array) get_post_meta( $event->ID, 'sp_team', false ); + $teams = array_filter( $teams ); + $teams = array_unique( $teams ); if ( ! empty( $teams ) ) { $event_results = get_post_meta( $event->ID, 'sp_results', true ); - foreach( $teams as $team_id ) { - if ( ! $team_id ) continue; + foreach ( $teams as $team_id ) { + if ( ! $team_id ) { + continue; + } $team = get_post( $team_id ); if ( $team ) { @@ -134,51 +140,57 @@ foreach ( $events as $event): } else { $summary = $event->post_title; } - - //Convert &#[0-9]+ entities to UTF-8 - $summary = preg_replace_callback("/(&#[0-9]+;)/", function($m) { return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); }, $summary); - + + // Convert &#[0-9]+ entities to UTF-8 + $summary = preg_replace_callback( + '/(&#[0-9]+;)/', + function( $m ) { + return mb_convert_encoding( $m[1], 'UTF-8', 'HTML-ENTITIES' ); + }, + $summary + ); + $summary = apply_filters( 'sportspress_ical_feed_summary', $summary, $event ); - + // Append to output string $output .= "BEGIN:VEVENT\r\n" . - "SUMMARY:" . preg_replace( '/([\,;])/','\\\$1', $summary ) . "\r\n" . + 'SUMMARY:' . preg_replace( '/([\,;])/', '\\\$1', $summary ) . "\r\n" . "UID:$event->ID\r\n" . "STATUS:CONFIRMED\r\n" . - "DTSTAMP:19700101T000000\r\n". - "DTSTART:" . mysql2date( $date_format, $event->post_date ) . "\r\n" . - "DTEND:" . $end->format( $date_format ) . "\r\n" . - "LAST-MODIFIED:" . mysql2date( $date_format, $event->post_modified_gmt ) . "\r\n"; + "DTSTAMP:19700101T000000\r\n" . + 'DTSTART:' . mysql2date( $date_format, $event->post_date ) . "\r\n" . + 'DTEND:' . $end->format( $date_format ) . "\r\n" . + 'LAST-MODIFIED:' . mysql2date( $date_format, $event->post_modified_gmt ) . "\r\n"; if ( $description ) { - $output .= "DESCRIPTION:" . $description . "\r\n"; + $output .= 'DESCRIPTION:' . $description . "\r\n"; } if ( $location ) { - $output .= "LOCATION:" . $location . "\r\n"; + $output .= 'LOCATION:' . $location . "\r\n"; } if ( $geo ) { - $output .= "GEO:" . $geo . "\r\n"; + $output .= 'GEO:' . $geo . "\r\n"; } $output .= "END:VEVENT\r\n"; endforeach; // End output -$output .= "END:VCALENDAR"; +$output .= 'END:VCALENDAR'; // Print headers -header('Content-type: text/calendar; charset=utf-8'); +header( 'Content-type: text/calendar; charset=utf-8' ); // The E-Tag is not being changed when the output file is generated – Some Webdav clients do not like this and // do not then 'see' that the file has changed – updates to the calendars are then not displayed to the user. // Props @garygomm https://wordpress.org/support/topic/calendar-feed-issue-not-updating-after-change/ -$etag = md5($output); -header('Etag:' . '"'.$etag.'"'); +$etag = md5( $output ); +header( 'Etag:' . '"' . $etag . '"' ); -header('Content-Disposition: inline; filename=' . $post->post_name . '.ics'); +header( 'Content-Disposition: inline; filename=' . $post->post_name . '.ics' ); // Print content echo wp_kses_post( $output ); diff --git a/includes/abstracts/abstract-sp-custom-post.php b/includes/abstracts/abstract-sp-custom-post.php index 2abe5dc9..9f4d632e 100644 --- a/includes/abstracts/abstract-sp-custom-post.php +++ b/includes/abstracts/abstract-sp-custom-post.php @@ -4,11 +4,11 @@ * * The SportsPress custom post class handles individual post data. * - * @class SP_Custom_Post - * @version 2.6.5 - * @package SportsPress/Abstracts - * @category Abstract Class - * @author ThemeBoy + * @class SP_Custom_Post + * @version 2.6.5 + * @package SportsPress/Abstracts + * @category Abstract Class + * @author ThemeBoy */ abstract class SP_Custom_Post { @@ -25,11 +25,11 @@ abstract class SP_Custom_Post { * @param mixed $post */ public function __construct( $post ) { - if ( $post instanceof WP_Post || $post instanceof SP_Custom_Post ): + if ( $post instanceof WP_Post || $post instanceof SP_Custom_Post ) : $this->ID = absint( $post->ID ); $this->post = $post; - else: - $this->ID = absint( $post ); + else : + $this->ID = absint( $post ); $this->post = get_post( $this->ID ); endif; } @@ -53,9 +53,9 @@ abstract class SP_Custom_Post { * @return bool */ public function __get( $key ) { - if ( ! isset( $key ) ): + if ( ! isset( $key ) ) : return $this->post; - else: + else : $value = get_post_meta( $this->ID, 'sp_' . $key, true ); endif; @@ -77,7 +77,7 @@ abstract class SP_Custom_Post { * * @access public * @param string $taxonomy The taxonomy. - * @return array|false|WP_Error See `get_the_terms()` + * @return array|false|WP_Error See `get_the_terms()` */ public function get_terms_sorted_by_sp_order( $taxonomy ) { $terms = get_the_terms( $this->ID, $taxonomy ); diff --git a/includes/abstracts/abstract-sp-secondary-post.php b/includes/abstracts/abstract-sp-secondary-post.php index 6294a351..ecfb9bc7 100644 --- a/includes/abstracts/abstract-sp-secondary-post.php +++ b/includes/abstracts/abstract-sp-secondary-post.php @@ -4,70 +4,70 @@ * * The SportsPress secondary post class extends custom posts with handling of secondary post types. * - * @class SP_Secondary_Post + * @class SP_Secondary_Post * @version 2.5.3 - * @package SportsPress/Abstracts - * @category Abstract Class - * @author ThemeBoy + * @package SportsPress/Abstracts + * @category Abstract Class + * @author ThemeBoy */ abstract class SP_Secondary_Post extends SP_Custom_Post { - /** @var string The date filter for events. */ - public $date = 0; + /** @var string The date filter for events. */ + public $date = 0; - /** @var string The date to range from. */ - public $from = 'now'; + /** @var string The date to range from. */ + public $from = 'now'; - /** @var string The date to range to. */ - public $to = 'now'; + /** @var string The date to range to. */ + public $to = 'now'; - /** @var string The number of days to query in the past. */ - public $past = 0; + /** @var string The number of days to query in the past. */ + public $past = 0; - /** @var string The number of days to query in the future. */ - public $future = 0; + /** @var string The number of days to query in the future. */ + public $future = 0; - /** @var boolean Determines whether the date range is relative. */ - public $relative = false; + /** @var boolean Determines whether the date range is relative. */ + public $relative = false; - /** - * __construct function. - * - * @access public - * @param mixed $post - */ - public function __construct( $post ) { - if ( $post instanceof WP_Post || $post instanceof SP_Secondary_Post ): - $this->ID = absint( $post->ID ); - $this->post = $post; - else: - $this->ID = absint( $post ); - $this->post = get_post( $this->ID ); - endif; - } + /** + * __construct function. + * + * @access public + * @param mixed $post + */ + public function __construct( $post ) { + if ( $post instanceof WP_Post || $post instanceof SP_Secondary_Post ) : + $this->ID = absint( $post->ID ); + $this->post = $post; + else : + $this->ID = absint( $post ); + $this->post = get_post( $this->ID ); + endif; + } - public function range( $where = '', $format = 'Y-m-d' ) { - $from = new DateTime( $this->from ); - $to = new DateTime( $this->to ); + public function range( $where = '', $format = 'Y-m-d' ) { + $from = new DateTime( $this->from ); + $to = new DateTime( $this->to ); - $to->modify( '+1 day' ); + $to->modify( '+1 day' ); - $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; + $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; - return $where; - } + return $where; + } - public function relative( $where = '', $format = 'Y-m-d' ) { - $from = new DateTime( 'now' ); - $to = new DateTime( 'now' ); + public function relative( $where = '', $format = 'Y-m-d' ) { + $from = new DateTime( 'now' ); + $to = new DateTime( 'now' ); - $from->modify( '-' . abs( (int) $this->past ) . ' day' ); - $to->modify( '+' . abs( (int) $this->future ) . ' day' ); + $from->modify( '-' . abs( (int) $this->past ) . ' day' ); + $to->modify( '+' . abs( (int) $this->future ) . ' day' ); - $to->modify( '+1 day' ); + $to->modify( '+1 day' ); - $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; + $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; - return $where; - } + return $where; + } } diff --git a/includes/admin/class-sp-admin-ajax.php b/includes/admin/class-sp-admin-ajax.php index e0118665..bfbc9fa4 100644 --- a/includes/admin/class-sp-admin-ajax.php +++ b/includes/admin/class-sp-admin-ajax.php @@ -6,10 +6,10 @@ if ( ! defined( 'ABSPATH' ) ) { /** * SportsPress Admin. * - * @class SP_Admin_AJAX - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin + * @class SP_Admin_AJAX + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin * @version 1.7 */ class SP_Admin_AJAX { @@ -59,10 +59,10 @@ class SP_Admin_AJAX { function save_inline_results() { check_ajax_referer( 'sp-save-inline-results', 'nonce' ); - $id = sp_array_value( $_POST, 'post_id' ); + $id = sp_array_value( $_POST, 'post_id' ); $results = sp_array_value( $_POST, 'results' ); - if ( sp_update_main_results ( $id, $results ) ) { + if ( sp_update_main_results( $id, $results ) ) { wp_send_json_success(); } else { wp_send_json_error(); diff --git a/includes/admin/class-sp-admin-assets.php b/includes/admin/class-sp-admin-assets.php index ed45b204..d2798874 100755 --- a/includes/admin/class-sp-admin-assets.php +++ b/includes/admin/class-sp-admin-assets.php @@ -2,144 +2,149 @@ /** * Load assets. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin * @version 2.6.15 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Assets' ) ) : -/** - * SP_Admin_Assets Class - */ -class SP_Admin_Assets { - /** - * Hook in tabs. + * SP_Admin_Assets Class */ - public function __construct() { - add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); - } + class SP_Admin_Assets { - /** - * Enqueue styles - */ - public function admin_styles( $hook ) { - // Sitewide menu CSS - wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION ); - - $screen = get_current_screen(); - - if ( in_array( $screen->id, sp_get_screen_ids() ) ) { - // Admin styles for SP pages only - wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' ); - wp_enqueue_style( 'wp-color-picker' ); - wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION ); - } elseif ( strpos( $screen->id, 'sportspress-config' ) !== false ) { - wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION ); + /** + * Hook in tabs. + */ + public function __construct() { + add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); } - if ( strpos( $screen->id, 'sportspress-overview' ) !== false ) { - wp_enqueue_style( 'sportspress-admin-slickmap', SP()->plugin_url() . '/assets/css/slickmap.css', array(), '1.1.0' ); + /** + * Enqueue styles + */ + public function admin_styles( $hook ) { + // Sitewide menu CSS + wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION ); + + $screen = get_current_screen(); + + if ( in_array( $screen->id, sp_get_screen_ids() ) ) { + // Admin styles for SP pages only + wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' ); + wp_enqueue_style( 'wp-color-picker' ); + wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION ); + } elseif ( strpos( $screen->id, 'sportspress-config' ) !== false ) { + wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION ); + } + + if ( strpos( $screen->id, 'sportspress-overview' ) !== false ) { + wp_enqueue_style( 'sportspress-admin-slickmap', SP()->plugin_url() . '/assets/css/slickmap.css', array(), '1.1.0' ); + } + + if ( in_array( $screen->id, array( 'dashboard' ) ) ) { + wp_enqueue_style( 'sportspress-admin-dashboard-styles', SP()->plugin_url() . '/assets/css/dashboard.css', array(), SP_VERSION ); + } + + if ( in_array( $screen->id, array( 'customize' ) ) ) { + wp_enqueue_style( 'sportspress-admin-customize-styles', SP()->plugin_url() . '/assets/css/customize.css', array(), SP_VERSION ); + } + + if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) { + wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION ); + } + + if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) || in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) { + wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' ); + wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION ); + } + + do_action( 'sportspress_admin_css', $screen ); } - if ( in_array( $screen->id, array( 'dashboard' ) ) ) { - wp_enqueue_style( 'sportspress-admin-dashboard-styles', SP()->plugin_url() . '/assets/css/dashboard.css', array(), SP_VERSION ); - } + /** + * Enqueue scripts + */ + public function admin_scripts( $hook ) { + global $wp_query, $post; - if ( in_array( $screen->id, array( 'customize' ) ) ) { - wp_enqueue_style( 'sportspress-admin-customize-styles', SP()->plugin_url() . '/assets/css/customize.css', array(), SP_VERSION ); - } + $screen = get_current_screen(); - if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) { - wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION ); - } + // Register scripts + wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true ); - if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) || in_array( $hook, array('post.php', 'post-new.php') ) ) { - wp_enqueue_style( 'jquery-ui-style' , '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' ); - wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION ); - } + wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true ); - do_action( 'sportspress_admin_css', $screen ); - } + wp_register_script( 'jquery-caret', SP()->plugin_url() . '/assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true ); - /** - * Enqueue scripts - */ - public function admin_scripts($hook) { - global $wp_query, $post; + wp_register_script( 'jquery-fitvids', SP()->plugin_url() . '/assets/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true ); - $screen = get_current_screen(); + wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true ); - // Register scripts - wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true ); + wp_register_script( 'sportspress-admin-colorpicker', SP()->plugin_url() . '/assets/js/admin/colorpicker.js', array( 'jquery', 'wp-color-picker', 'iris' ), SP_VERSION, true ); - wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true ); + wp_register_script( 'sportspress-admin-widgets', SP()->plugin_url() . '/assets/js/admin/widgets.js', array( 'jquery' ), SP_VERSION, true ); - wp_register_script( 'jquery-caret', SP()->plugin_url() . '/assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true ); + wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true ); - wp_register_script( 'jquery-fitvids', SP()->plugin_url() . '/assets/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true ); + // SportsPress admin pages + if ( in_array( $screen->id, sp_get_screen_ids() ) || strpos( $screen->id, 'sportspress-config' ) || in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) { - wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true ); + wp_enqueue_script( 'jquery' ); + wp_enqueue_script( 'chosen' ); + wp_enqueue_script( 'jquery-ui-core' ); + wp_enqueue_script( 'jquery-ui-draggable' ); + wp_enqueue_script( 'jquery-ui-droppable' ); + wp_enqueue_script( 'jquery-ui-sortable' ); + wp_enqueue_script( 'jquery-tiptip' ); + wp_enqueue_script( 'jquery-caret' ); + wp_enqueue_script( 'jquery-fitvids' ); + wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-fitvids' ), SP_VERSION, true ); - wp_register_script( 'sportspress-admin-colorpicker', SP()->plugin_url() . '/assets/js/admin/colorpicker.js', array( 'jquery', 'wp-color-picker', 'iris' ), SP_VERSION, true ); + $strings = apply_filters( + 'sportspress_localized_strings', + array( + 'none' => __( 'None', 'sportspress' ), + 'remove_text' => __( '— Remove —', 'sportspress' ), + 'days' => __( 'days', 'sportspress' ), + 'hrs' => __( 'hrs', 'sportspress' ), + 'mins' => __( 'mins', 'sportspress' ), + 'secs' => __( 'secs', 'sportspress' ), + 'displaying_posts' => html_entity_decode( __( 'Displaying %1$s–%2$s of %3$s', 'sportspress' ) ), + ) + ); - wp_register_script( 'sportspress-admin-widgets', SP()->plugin_url() . '/assets/js/admin/widgets.js', array( 'jquery' ), SP_VERSION, true ); + // Localize scripts + wp_localize_script( 'sportspress-admin', 'localized_strings', $strings ); + } - wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true ); + if ( in_array( $screen->id, array( 'widgets' ) ) ) { + wp_enqueue_script( 'sportspress-admin-widgets' ); + } - // SportsPress admin pages - if ( in_array( $screen->id, sp_get_screen_ids() ) || strpos( $screen->id, 'sportspress-config' ) || in_array($hook, array('post.php', 'post-new.php') ) ) { + // Edit color + if ( in_array( $screen->id, array( 'sp_outcome' ) ) ) { + wp_enqueue_script( 'sportspress-admin-colorpicker' ); + } - wp_enqueue_script( 'jquery' ); - wp_enqueue_script( 'chosen' ); - wp_enqueue_script( 'jquery-ui-core' ); - wp_enqueue_script( 'jquery-ui-draggable' ); - wp_enqueue_script( 'jquery-ui-droppable' ); - wp_enqueue_script( 'jquery-ui-sortable' ); - wp_enqueue_script( 'jquery-tiptip' ); - wp_enqueue_script( 'jquery-caret' ); - wp_enqueue_script( 'jquery-fitvids' ); - wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-fitvids' ), SP_VERSION, true ); - - $strings = apply_filters( 'sportspress_localized_strings', array( - 'none' => __( 'None', 'sportspress' ), - 'remove_text' => __( '— Remove —', 'sportspress' ), - 'days' => __( 'days', 'sportspress' ), - 'hrs' => __( 'hrs', 'sportspress' ), - 'mins' => __( 'mins', 'sportspress' ), - 'secs' => __( 'secs', 'sportspress' ), - 'displaying_posts' => html_entity_decode( __( 'Displaying %s–%s of %s', 'sportspress' ) ), - ) ); + // Edit equation + if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) { + wp_enqueue_script( 'sportspress-admin-equationbuilder' ); + } - // Localize scripts - wp_localize_script( 'sportspress-admin', 'localized_strings', $strings ); - } - - if ( in_array( $screen->id, array( 'widgets' ) ) ) { - wp_enqueue_script( 'sportspress-admin-widgets' ); - } - - // Edit color - if ( in_array( $screen->id, array( 'sp_outcome' ) ) ) { - wp_enqueue_script( 'sportspress-admin-colorpicker' ); - } - - // Edit equation - if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) { - wp_enqueue_script( 'sportspress-admin-equationbuilder' ); - } - - // Quick edit - if ( in_array( $screen->id, array( 'edit-sp_player' ) ) ) { - wp_enqueue_script( 'sportspress-admin-quickeditor' ); + // Quick edit + if ( in_array( $screen->id, array( 'edit-sp_player' ) ) ) { + wp_enqueue_script( 'sportspress-admin-quickeditor' ); + } } } -} endif; diff --git a/includes/admin/class-sp-admin-dashboard.php b/includes/admin/class-sp-admin-dashboard.php index 570ec260..1724df08 100644 --- a/includes/admin/class-sp-admin-dashboard.php +++ b/includes/admin/class-sp-admin-dashboard.php @@ -2,126 +2,130 @@ /** * Admin Dashboard * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin * @version 2.7.9 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Dashboard' ) ) : -/** - * SP_Admin_Dashboard Class - */ -class SP_Admin_Dashboard { + /** + * SP_Admin_Dashboard Class + */ + class SP_Admin_Dashboard { - /** - * Hook in tabs. - */ - public function __construct() { - // Only hook in admin parts if the user has admin access - if ( current_user_can( 'view_sportspress_reports' ) || current_user_can( 'manage_sportspress' ) || current_user_can( 'publish_sp_events' ) ) { - add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); - } - } + /** + * Hook in tabs. + */ + public function __construct() { + // Only hook in admin parts if the user has admin access + if ( current_user_can( 'view_sportspress_reports' ) || current_user_can( 'manage_sportspress' ) || current_user_can( 'publish_sp_events' ) ) { + add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); + } + } - /** - * Init dashboard widgets - */ - public function init() { - //wp_add_dashboard_widget( 'sportspress_dashboard_news', __( 'Sports News', 'sportspress' ), array( $this, 'news_widget' ), null, null, 'side' ); - wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress', 'sportspress' ), array( $this, 'status_widget' ) ); - add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 ); - } + /** + * Init dashboard widgets + */ + public function init() { + // wp_add_dashboard_widget( 'sportspress_dashboard_news', __( 'Sports News', 'sportspress' ), array( $this, 'news_widget' ), null, null, 'side' ); + wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress', 'sportspress' ), array( $this, 'status_widget' ) ); + add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 ); + } - /** - * Add links to At a Glance - */ - function glance_items( $items = array() ) { - $post_types = apply_filters( 'sportspress_glance_items', array( 'sp_event', 'sp_team', 'sp_player', 'sp_staff' ) ); - foreach ( $post_types as $type ): - if ( ! post_type_exists( $type ) ) continue; - $num_posts = wp_count_posts( $type ); - if ( $num_posts ): - $published = intval( $num_posts->publish ); - $post_type = get_post_type_object( $type ); - $text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'sportspress' ); - $text = sprintf( $text, number_format_i18n( $published ) ); - if ( current_user_can( $post_type->cap->edit_posts ) ): - $output = '' . $text . ''; - else: - $output = '' . $text . ''; - endif; - echo '
  • ' . esc_html( $output ) . '
  • '; - endif; - endforeach; - return $items; - } + /** + * Add links to At a Glance + */ + function glance_items( $items = array() ) { + $post_types = apply_filters( 'sportspress_glance_items', array( 'sp_event', 'sp_team', 'sp_player', 'sp_staff' ) ); + foreach ( $post_types as $type ) : + if ( ! post_type_exists( $type ) ) { + continue; + } + $num_posts = wp_count_posts( $type ); + if ( $num_posts ) : + $published = intval( $num_posts->publish ); + $post_type = get_post_type_object( $type ); + $text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'sportspress' ); + $text = sprintf( $text, number_format_i18n( $published ) ); + if ( current_user_can( $post_type->cap->edit_posts ) ) : + $output = '' . $text . ''; + else : + $output = '' . $text . ''; + endif; + echo '
  • ' . esc_html( $output ) . '
  • '; + endif; + endforeach; + return $items; + } - /** - * Show status widget - */ - public function status_widget() { - ?> - - + + get_item_quantity(5); - // Build an array of all the items, starting with element 0 (first element). - $rss_items = $rss->get_items(0, $maxitems); - } - if (!empty($maxitems)) { - ?> -
    - -
    - get_item_quantity( 5 ); + // Build an array of all the items, starting with element 0 (first element). + $rss_items = $rss->get_items( 0, $maxitems ); + } + if ( ! empty( $maxitems ) ) { + ?> +
    + +
    + plugin_path() . '/assets/js/admin/editor-lang.php'; - return $arr; + $arr['sp_shortcodes_button'] = SP()->plugin_path() . '/assets/js/admin/editor-lang.php'; + return $arr; } /** diff --git a/includes/admin/class-sp-admin-importers.php b/includes/admin/class-sp-admin-importers.php index 0ab69807..07f4dcb4 100644 --- a/includes/admin/class-sp-admin-importers.php +++ b/includes/admin/class-sp-admin-importers.php @@ -2,166 +2,172 @@ /** * Setup importers for SP data. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin - * @version 2.5.1 + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin + * @version 2.5.1 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Importers' ) ) : -/** - * SP_Admin_Importers Class - */ -class SP_Admin_Importers { - /** - * Hook in tabs. + * SP_Admin_Importers Class */ - public function __construct() { - add_action( 'admin_init', array( $this, 'register_importers' ) ); - } + class SP_Admin_Importers { - /** - * Add menu items - */ - public function register_importers() { - global $pagenow; - $importers = apply_filters( 'sportspress_importers', array( - 'sp_event_csv' => array( - 'name' => __( 'SportsPress Events (CSV)', 'sportspress' ), - 'description' => __( 'Import events from a csv file.', 'sportspress'), - 'callback' => array( $this, 'events_importer' ), - ), - 'sp_fixture_csv' => array( - 'name' => __( 'SportsPress Fixtures (CSV)', 'sportspress' ), - 'description' => __( 'Import upcoming events from a csv file.', 'sportspress'), - 'callback' => array( $this, 'fixtures_importer' ), - ), - 'sp_team_csv' => array( - 'name' => __( 'SportsPress Teams (CSV)', 'sportspress' ), - 'description' => __( 'Import teams from a csv file.', 'sportspress'), - 'callback' => array( $this, 'teams_importer' ), - ), - 'sp_player_csv' => array( - 'name' => __( 'SportsPress Players (CSV)', 'sportspress' ), - 'description' => __( 'Import players from a csv file.', 'sportspress'), - 'callback' => array( $this, 'players_importer' ), - ), - 'sp_staff_csv' => array( - 'name' => __( 'SportsPress Staff (CSV)', 'sportspress' ), - 'description' => __( 'Import staff from a csv file.', 'sportspress'), - 'callback' => array( $this, 'staff_importer' ), - ), - ) ); + /** + * Hook in tabs. + */ + public function __construct() { + add_action( 'admin_init', array( $this, 'register_importers' ) ); + } - if ( 'import.php' !== $pagenow ) { - $importers['sp_event_performance_csv'] = array( - 'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ), - 'description' => '' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '', - 'callback' => array( $this, 'event_performance_importer' ), + /** + * Add menu items + */ + public function register_importers() { + global $pagenow; + $importers = apply_filters( + 'sportspress_importers', + array( + 'sp_event_csv' => array( + 'name' => __( 'SportsPress Events (CSV)', 'sportspress' ), + 'description' => __( 'Import events from a csv file.', 'sportspress' ), + 'callback' => array( $this, 'events_importer' ), + ), + 'sp_fixture_csv' => array( + 'name' => __( 'SportsPress Fixtures (CSV)', 'sportspress' ), + 'description' => __( 'Import upcoming events from a csv file.', 'sportspress' ), + 'callback' => array( $this, 'fixtures_importer' ), + ), + 'sp_team_csv' => array( + 'name' => __( 'SportsPress Teams (CSV)', 'sportspress' ), + 'description' => __( 'Import teams from a csv file.', 'sportspress' ), + 'callback' => array( $this, 'teams_importer' ), + ), + 'sp_player_csv' => array( + 'name' => __( 'SportsPress Players (CSV)', 'sportspress' ), + 'description' => __( 'Import players from a csv file.', 'sportspress' ), + 'callback' => array( $this, 'players_importer' ), + ), + 'sp_staff_csv' => array( + 'name' => __( 'SportsPress Staff (CSV)', 'sportspress' ), + 'description' => __( 'Import staff from a csv file.', 'sportspress' ), + 'callback' => array( $this, 'staff_importer' ), + ), + ) ); + + if ( 'import.php' !== $pagenow ) { + $importers['sp_event_performance_csv'] = array( + 'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ), + 'description' => '' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '', + 'callback' => array( $this, 'event_performance_importer' ), + ); + } + + foreach ( $importers as $id => $importer ) { + register_importer( $id, $importer['name'], $importer['description'], $importer['callback'] ); + } } - foreach ( $importers as $id => $importer ) { - register_importer( $id, $importer['name'], $importer['description'], $importer['callback'] ); + /** + * Add menu item + */ + public function events_importer() { + $this->includes(); + + require 'importers/class-sp-event-importer.php'; + + // Dispatch + $importer = new SP_Event_Importer(); + $importer->dispatch(); + } + + /** + * Add menu item + */ + public function event_performance_importer() { + $this->includes(); + + require 'importers/class-sp-event-performance-importer.php'; + + // Dispatch + $importer = new SP_Event_Performance_Importer(); + $importer->dispatch(); + } + + /** + * Add menu item + */ + public function fixtures_importer() { + $this->includes(); + + require 'importers/class-sp-fixture-importer.php'; + + // Dispatch + $importer = new SP_Fixture_Importer(); + $importer->dispatch(); + } + + /** + * Add menu item + */ + public function teams_importer() { + $this->includes(); + + require 'importers/class-sp-team-importer.php'; + + // Dispatch + $importer = new SP_Team_Importer(); + $importer->dispatch(); + } + + /** + * Add menu item + */ + public function players_importer() { + $this->includes(); + + require 'importers/class-sp-player-importer.php'; + + // Dispatch + $importer = new SP_Player_Importer(); + $importer->dispatch(); + } + + /** + * Add menu item + */ + public function staff_importer() { + $this->includes(); + + require 'importers/class-sp-staff-importer.php'; + + // Dispatch + $importer = new SP_Staff_Importer(); + $importer->dispatch(); + } + + public static function includes() { + // Load Importer API + require_once ABSPATH . 'wp-admin/includes/import.php'; + + if ( ! class_exists( 'WP_Importer' ) ) { + $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; + if ( file_exists( $class_wp_importer ) ) { + require $class_wp_importer; + } + } + + require 'importers/class-sp-importer.php'; } } - /** - * Add menu item - */ - public function events_importer() { - $this->includes(); - - require 'importers/class-sp-event-importer.php'; - - // Dispatch - $importer = new SP_Event_Importer(); - $importer->dispatch(); - } - - /** - * Add menu item - */ - public function event_performance_importer() { - $this->includes(); - - require 'importers/class-sp-event-performance-importer.php'; - - // Dispatch - $importer = new SP_Event_Performance_Importer(); - $importer->dispatch(); - } - - /** - * Add menu item - */ - public function fixtures_importer() { - $this->includes(); - - require 'importers/class-sp-fixture-importer.php'; - - // Dispatch - $importer = new SP_Fixture_Importer(); - $importer->dispatch(); - } - - /** - * Add menu item - */ - public function teams_importer() { - $this->includes(); - - require 'importers/class-sp-team-importer.php'; - - // Dispatch - $importer = new SP_Team_Importer(); - $importer->dispatch(); - } - - /** - * Add menu item - */ - public function players_importer() { - $this->includes(); - - require 'importers/class-sp-player-importer.php'; - - // Dispatch - $importer = new SP_Player_Importer(); - $importer->dispatch(); - } - - /** - * Add menu item - */ - public function staff_importer() { - $this->includes(); - - require 'importers/class-sp-staff-importer.php'; - - // Dispatch - $importer = new SP_Staff_Importer(); - $importer->dispatch(); - } - - public static function includes() { - // Load Importer API - require_once ABSPATH . 'wp-admin/includes/import.php'; - - if ( ! class_exists( 'WP_Importer' ) ) { - $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; - if ( file_exists( $class_wp_importer ) ) - require $class_wp_importer; - } - - require 'importers/class-sp-importer.php'; - } -} - endif; -return new SP_Admin_Importers(); \ No newline at end of file +return new SP_Admin_Importers(); diff --git a/includes/admin/class-sp-admin-menus.php b/includes/admin/class-sp-admin-menus.php index b4a302c8..60a68961 100755 --- a/includes/admin/class-sp-admin-menus.php +++ b/includes/admin/class-sp-admin-menus.php @@ -2,283 +2,293 @@ /** * Setup menus in WP admin. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin - * @version 2.7.9 + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin + * @version 2.7.9 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Menus' ) ) : -/** - * SP_Admin_Menus Class - */ -class SP_Admin_Menus { - /** - * Hook in tabs. + * SP_Admin_Menus Class */ - public function __construct() { - add_filter( 'admin_menu', array( $this, 'menu_clean' ), 5 ); - add_action( 'admin_menu', array( $this, 'admin_menu' ), 6 ); - add_action( 'admin_menu', array( $this, 'config_menu' ), 7 ); - add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 ); - add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 ); + class SP_Admin_Menus { - add_action( 'admin_head', array( $this, 'menu_highlight' ) ); - add_action( 'admin_head', array( $this, 'menu_rename' ) ); - add_action( 'parent_file', array( $this, 'parent_file' ) ); - add_filter( 'menu_order', array( $this, 'menu_order' ) ); - add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) ); - add_filter( 'sportspress_sitemap_taxonomy_post_types', array( $this, 'sitemap_taxonomy_post_types' ), 10, 2 ); - } + /** + * Hook in tabs. + */ + public function __construct() { + add_filter( 'admin_menu', array( $this, 'menu_clean' ), 5 ); + add_action( 'admin_menu', array( $this, 'admin_menu' ), 6 ); + add_action( 'admin_menu', array( $this, 'config_menu' ), 7 ); + add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 ); + add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 ); - /** - * Add menu item - */ - public function admin_menu() { - global $menu; - - if ( current_user_can( 'manage_sportspress' ) ) - $menu[] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' ); - - $main_page = add_menu_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_sportspress', 'sportspress', array( $this, 'settings_page' ), apply_filters( 'sportspress_menu_icon', null ), '51.5' ); - } - - /** - * Add menu item - */ - public function config_menu() { - add_submenu_page( 'sportspress', __( 'Configure', 'sportspress' ), __( 'Configure', 'sportspress' ), 'manage_sportspress', 'sportspress-config', array( $this, 'config_page' ) ); - } - - /** - * Add menu item - */ - public function leagues_menu() { - add_submenu_page( 'sportspress', __( 'Leagues', 'sportspress' ), __( 'Leagues', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_league'); - } - - /** - * Add menu item - */ - public function seasons_menu() { - add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season'); - } - - /** - * Highlights the correct top level admin menu item for post type add screens. - * - * @access public - * @return void - */ - public function menu_highlight() { - global $typenow; - $screen = get_current_screen(); - if ( ! is_object( $screen ) ) return; - if ( $screen->id == 'sp_role' ) { - $this->highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit-tags.php?taxonomy=sp_role&post_type=sp_staff' ); - } elseif ( is_sp_config_type( $typenow ) ) { - $this->highlight_admin_menu( 'sportspress', 'sportspress-config' ); - } elseif ( $typenow == 'sp_calendar' ) { - $this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' ); - } elseif ( $typenow == 'sp_table' ) { - $this->highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' ); - } elseif ( $typenow == 'sp_list' ) { - $this->highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' ); + add_action( 'admin_head', array( $this, 'menu_highlight' ) ); + add_action( 'admin_head', array( $this, 'menu_rename' ) ); + add_action( 'parent_file', array( $this, 'parent_file' ) ); + add_filter( 'menu_order', array( $this, 'menu_order' ) ); + add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) ); + add_filter( 'sportspress_sitemap_taxonomy_post_types', array( $this, 'sitemap_taxonomy_post_types' ), 10, 2 ); } - } - /** - * Renames admin menu items. - * - * @access public - * @return void - */ - public function menu_rename() { - global $menu, $submenu; + /** + * Add menu item + */ + public function admin_menu() { + global $menu; - if ( isset( $submenu['sportspress'] ) && isset( $submenu['sportspress'][0] ) && isset( $submenu['sportspress'][0][0] ) ) - $submenu['sportspress'][0][0] = __( 'Settings', 'sportspress' ); - } + if ( current_user_can( 'manage_sportspress' ) ) { + $menu[] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' ); + } - public function parent_file( $parent_file ) { - global $current_screen; - $taxonomy = $current_screen->taxonomy; - if ( in_array( $taxonomy, array( 'sp_league', 'sp_season' ) ) ) - $parent_file = 'sportspress'; - return $parent_file; - } + $main_page = add_menu_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_sportspress', 'sportspress', array( $this, 'settings_page' ), apply_filters( 'sportspress_menu_icon', null ), '51.5' ); + } - /** - * Reorder the SP menu items in admin. - * - * @param mixed $menu_order - * @return array - */ - public function menu_order( $menu_order ) { - // Initialize our custom order array - $sportspress_menu_order = array(); + /** + * Add menu item + */ + public function config_menu() { + add_submenu_page( 'sportspress', __( 'Configure', 'sportspress' ), __( 'Configure', 'sportspress' ), 'manage_sportspress', 'sportspress-config', array( $this, 'config_page' ) ); + } - // Get the index of our custom separator - $sportspress_separator = array_search( 'separator-sportspress', $menu_order ); + /** + * Add menu item + */ + public function leagues_menu() { + add_submenu_page( 'sportspress', __( 'Leagues', 'sportspress' ), __( 'Leagues', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_league' ); + } - // Get index of menu items - $sportspress_event = array_search( 'edit.php?post_type=sp_event', $menu_order ); - $sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order ); - $sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order ); - $sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order ); + /** + * Add menu item + */ + public function seasons_menu() { + add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season' ); + } - // Loop through menu order and do some rearranging - foreach ( $menu_order as $index => $item ): + /** + * Highlights the correct top level admin menu item for post type add screens. + * + * @access public + * @return void + */ + public function menu_highlight() { + global $typenow; + $screen = get_current_screen(); + if ( ! is_object( $screen ) ) { + return; + } + if ( $screen->id == 'sp_role' ) { + $this->highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit-tags.php?taxonomy=sp_role&post_type=sp_staff' ); + } elseif ( is_sp_config_type( $typenow ) ) { + $this->highlight_admin_menu( 'sportspress', 'sportspress-config' ); + } elseif ( $typenow == 'sp_calendar' ) { + $this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' ); + } elseif ( $typenow == 'sp_table' ) { + $this->highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' ); + } elseif ( $typenow == 'sp_list' ) { + $this->highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' ); + } + } - if ( ( ( 'sportspress' ) == $item ) ): - $sportspress_menu_order[] = 'separator-sportspress'; - $sportspress_menu_order[] = $item; - $sportspress_menu_order[] = 'edit.php?post_type=sp_event'; - $sportspress_menu_order[] = 'edit.php?post_type=sp_team'; - $sportspress_menu_order[] = 'edit.php?post_type=sp_player'; - $sportspress_menu_order[] = 'edit.php?post_type=sp_staff'; - unset( $menu_order[ $sportspress_separator ] ); - unset( $menu_order[ $sportspress_event ] ); - unset( $menu_order[ $sportspress_team ] ); - unset( $menu_order[ $sportspress_player ] ); - unset( $menu_order[ $sportspress_staff ] ); + /** + * Renames admin menu items. + * + * @access public + * @return void + */ + public function menu_rename() { + global $menu, $submenu; - // Apply to added menu items - $menu_items = apply_filters( 'sportspress_menu_items', array() ); - foreach ( $menu_items as $menu_item ): - $sportspress_menu_order[] = $menu_item; - $index = array_search( $menu_item, $menu_order ); - unset( $menu_order[ $index ] ); - endforeach; + if ( isset( $submenu['sportspress'] ) && isset( $submenu['sportspress'][0] ) && isset( $submenu['sportspress'][0][0] ) ) { + $submenu['sportspress'][0][0] = __( 'Settings', 'sportspress' ); + } + } - elseif ( !in_array( $item, array( 'separator-sportspress' ) ) ) : - $sportspress_menu_order[] = $item; + public function parent_file( $parent_file ) { + global $current_screen; + $taxonomy = $current_screen->taxonomy; + if ( in_array( $taxonomy, array( 'sp_league', 'sp_season' ) ) ) { + $parent_file = 'sportspress'; + } + return $parent_file; + } + + /** + * Reorder the SP menu items in admin. + * + * @param mixed $menu_order + * @return array + */ + public function menu_order( $menu_order ) { + // Initialize our custom order array + $sportspress_menu_order = array(); + + // Get the index of our custom separator + $sportspress_separator = array_search( 'separator-sportspress', $menu_order ); + + // Get index of menu items + $sportspress_event = array_search( 'edit.php?post_type=sp_event', $menu_order ); + $sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order ); + $sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order ); + $sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order ); + + // Loop through menu order and do some rearranging + foreach ( $menu_order as $index => $item ) : + + if ( ( ( 'sportspress' ) == $item ) ) : + $sportspress_menu_order[] = 'separator-sportspress'; + $sportspress_menu_order[] = $item; + $sportspress_menu_order[] = 'edit.php?post_type=sp_event'; + $sportspress_menu_order[] = 'edit.php?post_type=sp_team'; + $sportspress_menu_order[] = 'edit.php?post_type=sp_player'; + $sportspress_menu_order[] = 'edit.php?post_type=sp_staff'; + unset( $menu_order[ $sportspress_separator ] ); + unset( $menu_order[ $sportspress_event ] ); + unset( $menu_order[ $sportspress_team ] ); + unset( $menu_order[ $sportspress_player ] ); + unset( $menu_order[ $sportspress_staff ] ); + + // Apply to added menu items + $menu_items = apply_filters( 'sportspress_menu_items', array() ); + foreach ( $menu_items as $menu_item ) : + $sportspress_menu_order[] = $menu_item; + $index = array_search( $menu_item, $menu_order ); + unset( $menu_order[ $index ] ); + endforeach; + + elseif ( ! in_array( $item, array( 'separator-sportspress' ) ) ) : + $sportspress_menu_order[] = $item; + endif; + + endforeach; + + // Return order + return $sportspress_menu_order; + } + + /** + * custom_menu_order + * + * @return bool + */ + public function custom_menu_order() { + if ( ! current_user_can( 'manage_sportspress' ) ) { + return false; + } + return true; + } + + /** + * Clean the SP menu items in admin. + */ + public function menu_clean() { + global $menu, $submenu, $current_user; + + // Find where our separator is in the menu + foreach ( $menu as $key => $data ) : + if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' ) { + $separator_position = $key; + } + endforeach; + + // Swap our separator post type with a menu separator + if ( isset( $separator_position ) ) : + $menu[ $separator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' ); endif; - endforeach; + // Remove "Leagues" and "Seasons" links from Events submenu + if ( isset( $submenu['edit.php?post_type=sp_event'] ) ) : + $submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_leagues' ) ); + $submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_seasons' ) ); + endif; - // Return order - return $sportspress_menu_order; + // Remove "Venues", "Leagues" and "Seasons" links from Teams submenu + if ( isset( $submenu['edit.php?post_type=sp_team'] ) ) : + $submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_venues' ) ); + $submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_leagues' ) ); + $submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_seasons' ) ); + endif; + + // Remove "Leagues" and "Seasons" links from Players submenu + if ( isset( $submenu['edit.php?post_type=sp_player'] ) ) : + $submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_leagues' ) ); + $submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_seasons' ) ); + endif; + + // Remove "Leagues" and "Seasons" links from Staff submenu + if ( isset( $submenu['edit.php?post_type=sp_staff'] ) ) : + $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_leagues' ) ); + $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) ); + endif; + + $user_roles = $current_user->roles; + $user_role = array_shift( $user_roles ); + + if ( in_array( $user_role, array( 'sp_player', 'sp_staff', 'sp_event_manager', 'sp_team_manager' ) ) ) : + remove_menu_page( 'upload.php' ); + remove_menu_page( 'edit-comments.php' ); + remove_menu_page( 'tools.php' ); + endif; + } + + /** + * Init the config page + */ + public function config_page() { + include 'views/html-admin-config.php'; + } + + /** + * Init the settings page + */ + public function settings_page() { + include_once 'class-sp-admin-settings.php'; + SP_Admin_Settings::output(); + } + + public function remove_add_new( $arr = array() ) { + return $arr[0] != __( 'Add New', 'sportspress' ); + } + + public function remove_leagues( $arr = array() ) { + return $arr[0] != __( 'Leagues', 'sportspress' ); + } + + public function remove_positions( $arr = array() ) { + return $arr[0] != __( 'Positions', 'sportspress' ); + } + + public function remove_seasons( $arr = array() ) { + return $arr[0] != __( 'Seasons', 'sportspress' ); + } + + public function remove_venues( $arr = array() ) { + return $arr[0] != __( 'Venues', 'sportspress' ); + } + + public static function highlight_admin_menu( $p = 'sportspress', $s = 'sportspress' ) { + global $parent_file, $submenu_file; + $parent_file = $p; + $submenu_file = $s; + } + + public static function sitemap_taxonomy_post_types( $post_types = array(), $taxonomy = 'sp_venue' ) { + $post_types = array_intersect( $post_types, sp_primary_post_types() ); + // Remove teams from venues taxonomy post type array + if ( $taxonomy === 'sp_venue' && ( $key = array_search( 'sp_team', $post_types ) ) !== false ) : + unset( $post_types[ $key ] ); + endif; + + return $post_types; + } } - /** - * custom_menu_order - * @return bool - */ - public function custom_menu_order() { - if ( ! current_user_can( 'manage_sportspress' ) ) - return false; - return true; - } - - /** - * Clean the SP menu items in admin. - */ - public function menu_clean() { - global $menu, $submenu, $current_user; - - // Find where our separator is in the menu - foreach( $menu as $key => $data ): - if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' ) - $separator_position = $key; - endforeach; - - // Swap our separator post type with a menu separator - if ( isset( $separator_position ) ): - $menu[ $separator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' ); - endif; - - // Remove "Leagues" and "Seasons" links from Events submenu - if ( isset( $submenu['edit.php?post_type=sp_event'] ) ): - $submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_leagues' ) ); - $submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_seasons' ) ); - endif; - - // Remove "Venues", "Leagues" and "Seasons" links from Teams submenu - if ( isset( $submenu['edit.php?post_type=sp_team'] ) ): - $submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_venues' ) ); - $submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_leagues' ) ); - $submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_seasons' ) ); - endif; - - // Remove "Leagues" and "Seasons" links from Players submenu - if ( isset( $submenu['edit.php?post_type=sp_player'] ) ): - $submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_leagues' ) ); - $submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_seasons' ) ); - endif; - - // Remove "Leagues" and "Seasons" links from Staff submenu - if ( isset( $submenu['edit.php?post_type=sp_staff'] ) ): - $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_leagues' ) ); - $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) ); - endif; - - $user_roles = $current_user->roles; - $user_role = array_shift($user_roles); - - if ( in_array( $user_role, array( 'sp_player', 'sp_staff', 'sp_event_manager', 'sp_team_manager' ) ) ): - remove_menu_page( 'upload.php' ); - remove_menu_page( 'edit-comments.php' ); - remove_menu_page( 'tools.php' ); - endif; - } - - /** - * Init the config page - */ - public function config_page() { - include( 'views/html-admin-config.php' ); - } - - /** - * Init the settings page - */ - public function settings_page() { - include_once( 'class-sp-admin-settings.php' ); - SP_Admin_Settings::output(); - } - - public function remove_add_new( $arr = array() ) { - return $arr[0] != __( 'Add New', 'sportspress' ); - } - - public function remove_leagues( $arr = array() ) { - return $arr[0] != __( 'Leagues', 'sportspress' ); - } - - public function remove_positions( $arr = array() ) { - return $arr[0] != __( 'Positions', 'sportspress' ); - } - - public function remove_seasons( $arr = array() ) { - return $arr[0] != __( 'Seasons', 'sportspress' ); - } - - public function remove_venues( $arr = array() ) { - return $arr[0] != __( 'Venues', 'sportspress' ); - } - - public static function highlight_admin_menu( $p = 'sportspress', $s = 'sportspress' ) { - global $parent_file, $submenu_file; - $parent_file = $p; - $submenu_file = $s; - } - - public static function sitemap_taxonomy_post_types( $post_types = array(), $taxonomy = 'sp_venue' ) { - $post_types = array_intersect( $post_types, sp_primary_post_types() ); - // Remove teams from venues taxonomy post type array - if ( $taxonomy === 'sp_venue' && ( $key = array_search( 'sp_team', $post_types ) ) !== false ): - unset( $post_types[ $key ] ); - endif; - - return $post_types; - } -} - endif; return new SP_Admin_Menus(); diff --git a/includes/admin/class-sp-admin-notices.php b/includes/admin/class-sp-admin-notices.php index f8584246..3a13ee23 100644 --- a/includes/admin/class-sp-admin-notices.php +++ b/includes/admin/class-sp-admin-notices.php @@ -2,145 +2,149 @@ /** * Display notices in admin. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin * @version 2.3 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Notices' ) ) : -/** - * SP_Admin_Notices Class - */ -class SP_Admin_Notices { - /** - * Hook in tabs. + * SP_Admin_Notices Class */ - public function __construct() { - add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) ); - add_action( 'sportspress_updated', array( $this, 'reset_admin_notices' ) ); - add_action( 'admin_print_styles', array( $this, 'add_notices' ) ); - } + class SP_Admin_Notices { - /** - * Reset notices for themes when switched or a new version of SP is installed - */ - public function reset_admin_notices() { - update_option( 'sportspress_admin_notices', array( 'template_files', 'theme_support' ) ); - } - - /** - * Add notices + styles if needed. - */ - public function add_notices() { - $screen = get_current_screen(); - $notices = get_option( 'sportspress_admin_notices', array() ); - - if ( ! is_object( $screen ) ) return; - - if ( ! get_option( 'sportspress_completed_setup' ) && ! in_array( $screen->id, array( 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) { - wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) ); - add_action( 'admin_notices', array( $this, 'setup_notice' ) ); + /** + * Hook in tabs. + */ + public function __construct() { + add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) ); + add_action( 'sportspress_updated', array( $this, 'reset_admin_notices' ) ); + add_action( 'admin_print_styles', array( $this, 'add_notices' ) ); } - if ( 'post' == $screen->base ) { - $post_id = get_the_ID(); - if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) { - add_action( 'admin_notices', array( $this, 'no_access_notice' ) ); - } + /** + * Reset notices for themes when switched or a new version of SP is installed + */ + public function reset_admin_notices() { + update_option( 'sportspress_admin_notices', array( 'template_files', 'theme_support' ) ); } - if ( ! empty( $_GET['hide_theme_support_notice'] ) ) { - $notices = array_diff( $notices, array( 'theme_support' ) ); - update_option( 'sportspress_admin_notices', $notices ); - } + /** + * Add notices + styles if needed. + */ + public function add_notices() { + $screen = get_current_screen(); + $notices = get_option( 'sportspress_admin_notices', array() ); - if ( ! empty( $_GET['hide_template_files_notice'] ) ) { - $notices = array_diff( $notices, array( 'template_files' ) ); - update_option( 'sportspress_admin_notices', $notices ); - } - - if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'sportspress' ) && ! in_array( $screen->id, array( 'toplevel_page_sportspress', 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) { - $template = get_option( 'template' ); - - if ( ! in_array( $template, array( 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) { - wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) ); - add_action( 'admin_notices', array( $this, 'theme_check_notice' ) ); - } - } - - if ( in_array( 'template_files', $notices ) ) { - wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) ); - add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) ); - } - } - - /** - * Show the setup notices - */ - public function setup_notice() { - include( 'views/html-notice-install.php' ); - } - - /** - * Displays a notice when the user doesn't have access to edit a post type - */ - public function no_access_notice() { - include( 'views/html-notice-no-access.php' ); - } - - /** - * Show the Theme Check notice - */ - public function theme_check_notice() { - include( 'views/html-notice-theme-support.php' ); - } - - /** - * Show a notice highlighting bad template files - */ - public function template_file_check_notice() { - if ( isset( $_GET['page'] ) && 'sportspress' == $_GET['page'] && isset( $_GET['tab'] ) && 'status' == $_GET['tab'] ) { - return; - } - - $status = include( 'class-sp-admin-status.php' ); - $core_templates = $status->scan_template_files( SP()->plugin_path() . '/templates' ); - $outdated = false; - - foreach ( $core_templates as $file ) { - $theme_file = false; - if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { - $theme_file = get_stylesheet_directory() . '/' . $file; - } elseif ( file_exists( get_stylesheet_directory() . '/sportspress/' . $file ) ) { - $theme_file = get_stylesheet_directory() . '/sportspress/' . $file; - } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { - $theme_file = get_template_directory() . '/' . $file; - } elseif( file_exists( get_template_directory() . '/sportspress/' . $file ) ) { - $theme_file = get_template_directory() . '/sportspress/' . $file; + if ( ! is_object( $screen ) ) { + return; } - if ( $theme_file ) { - $core_version = $status->get_file_version( SP()->plugin_path() . '/templates/' . $file ); - $theme_version = $status->get_file_version( $theme_file ); + if ( ! get_option( 'sportspress_completed_setup' ) && ! in_array( $screen->id, array( 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) { + wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) ); + add_action( 'admin_notices', array( $this, 'setup_notice' ) ); + } - if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) { - $outdated = true; - break; + if ( 'post' == $screen->base ) { + $post_id = get_the_ID(); + if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) { + add_action( 'admin_notices', array( $this, 'no_access_notice' ) ); } } + + if ( ! empty( $_GET['hide_theme_support_notice'] ) ) { + $notices = array_diff( $notices, array( 'theme_support' ) ); + update_option( 'sportspress_admin_notices', $notices ); + } + + if ( ! empty( $_GET['hide_template_files_notice'] ) ) { + $notices = array_diff( $notices, array( 'template_files' ) ); + update_option( 'sportspress_admin_notices', $notices ); + } + + if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'sportspress' ) && ! in_array( $screen->id, array( 'toplevel_page_sportspress', 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) { + $template = get_option( 'template' ); + + if ( ! in_array( $template, array( 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) { + wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) ); + add_action( 'admin_notices', array( $this, 'theme_check_notice' ) ); + } + } + + if ( in_array( 'template_files', $notices ) ) { + wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) ); + add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) ); + } } - if ( $outdated ) { - include( 'views/html-notice-template-check.php' ); + /** + * Show the setup notices + */ + public function setup_notice() { + include 'views/html-notice-install.php'; + } + + /** + * Displays a notice when the user doesn't have access to edit a post type + */ + public function no_access_notice() { + include 'views/html-notice-no-access.php'; + } + + /** + * Show the Theme Check notice + */ + public function theme_check_notice() { + include 'views/html-notice-theme-support.php'; + } + + /** + * Show a notice highlighting bad template files + */ + public function template_file_check_notice() { + if ( isset( $_GET['page'] ) && 'sportspress' == $_GET['page'] && isset( $_GET['tab'] ) && 'status' == $_GET['tab'] ) { + return; + } + + $status = include 'class-sp-admin-status.php'; + $core_templates = $status->scan_template_files( SP()->plugin_path() . '/templates' ); + $outdated = false; + + foreach ( $core_templates as $file ) { + $theme_file = false; + if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { + $theme_file = get_stylesheet_directory() . '/' . $file; + } elseif ( file_exists( get_stylesheet_directory() . '/sportspress/' . $file ) ) { + $theme_file = get_stylesheet_directory() . '/sportspress/' . $file; + } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { + $theme_file = get_template_directory() . '/' . $file; + } elseif ( file_exists( get_template_directory() . '/sportspress/' . $file ) ) { + $theme_file = get_template_directory() . '/sportspress/' . $file; + } + + if ( $theme_file ) { + $core_version = $status->get_file_version( SP()->plugin_path() . '/templates/' . $file ); + $theme_version = $status->get_file_version( $theme_file ); + + if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) { + $outdated = true; + break; + } + } + } + + if ( $outdated ) { + include 'views/html-notice-template-check.php'; + } } } -} endif; -return new SP_Admin_Notices(); \ No newline at end of file +return new SP_Admin_Notices(); diff --git a/includes/admin/class-sp-admin-permalink-settings.php b/includes/admin/class-sp-admin-permalink-settings.php index d2454c1b..73492305 100644 --- a/includes/admin/class-sp-admin-permalink-settings.php +++ b/includes/admin/class-sp-admin-permalink-settings.php @@ -2,102 +2,111 @@ /** * Adds settings to the permalinks admin settings page. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin - * @version 2.7.9 + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin + * @version 2.7.9 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Permalink_Settings' ) ) : -/** - * SP_Admin_Permalink_Settings Class - */ -class SP_Admin_Permalink_Settings { - /** - * Hook in tabs. + * SP_Admin_Permalink_Settings Class */ - public function __construct() { - $this->slugs = apply_filters( 'sportspress_permalink_slugs', array( - array( 'event', __( 'Events', 'sportspress' ) ), - array( 'venue', __( 'Venues', 'sportspress' ) ), - array( 'calendar', __( 'Calendars', 'sportspress' ) ), - array( 'team', __( 'Teams', 'sportspress' ) ), - array( 'league', __( 'Leagues', 'sportspress' ) ), - array( 'season', __( 'Seasons', 'sportspress' ) ), - array( 'table', __( 'League Tables', 'sportspress' ) ), - array( 'player', __( 'Players', 'sportspress' ) ), - array( 'position', __( 'Positions', 'sportspress' ) ), - array( 'list', __( 'Player Lists', 'sportspress' ) ), - array( 'staff', __( 'Staff', 'sportspress' ) ), - ) ); + class SP_Admin_Permalink_Settings { - add_action( 'admin_init', array( $this, 'settings_init' ) ); - add_action( 'admin_init', array( $this, 'settings_save' ) ); - } - - /** - * Init our settings - */ - public function settings_init() { - // Add a section to the permalinks page - add_settings_section( 'sportspress-permalink', __( 'SportsPress', 'sportspress' ), array( $this, 'settings' ), 'permalink' ); - - // Add our settings - foreach ( $this->slugs as $slug ): - add_settings_field( - $slug[0], // id - $slug[1], // setting title - array( $this, 'slug_input' ), // display callback - 'permalink', // settings page - 'sportspress-permalink' // settings section + /** + * Hook in tabs. + */ + public function __construct() { + $this->slugs = apply_filters( + 'sportspress_permalink_slugs', + array( + array( 'event', __( 'Events', 'sportspress' ) ), + array( 'venue', __( 'Venues', 'sportspress' ) ), + array( 'calendar', __( 'Calendars', 'sportspress' ) ), + array( 'team', __( 'Teams', 'sportspress' ) ), + array( 'league', __( 'Leagues', 'sportspress' ) ), + array( 'season', __( 'Seasons', 'sportspress' ) ), + array( 'table', __( 'League Tables', 'sportspress' ) ), + array( 'player', __( 'Players', 'sportspress' ) ), + array( 'position', __( 'Positions', 'sportspress' ) ), + array( 'list', __( 'Player Lists', 'sportspress' ) ), + array( 'staff', __( 'Staff', 'sportspress' ) ), + ) ); - endforeach; - } - /** - * Show a slug input box. - */ - public function slug_input() { - $slug = array_shift( $this->slugs ); - $key = $slug[0]; - $text = get_option( 'sportspress_' . $key . '_slug', null ); - ?>
    not using "default" permalinks above.', 'sportspress' ) ); - } + /** + * Init our settings + */ + public function settings_init() { + // Add a section to the permalinks page + add_settings_section( 'sportspress-permalink', __( 'SportsPress', 'sportspress' ), array( $this, 'settings' ), 'permalink' ); - /** - * Save the settings - */ - public function settings_save() { - if ( ! is_admin() ) - return; - - if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['sportspress_event_slug'] ) ): - foreach ( $this->slugs as $slug ): - $key = 'sportspress_' . $slug[0] . '_slug'; - $value = null; - if ( isset( $_POST[ $key ] ) ) - $value = sanitize_text_field( $_POST[ $key ] ); - if ( empty( $value ) ) - delete_option( $key ); - else - update_option( $key, $value ); + // Add our settings + foreach ( $this->slugs as $slug ) : + add_settings_field( + $slug[0], // id + $slug[1], // setting title + array( $this, 'slug_input' ), // display callback + 'permalink', // settings page + 'sportspress-permalink' // settings section + ); endforeach; - sp_flush_rewrite_rules(); - endif; + } + + /** + * Show a slug input box. + */ + public function slug_input() { + $slug = array_shift( $this->slugs ); + $key = $slug[0]; + $text = get_option( 'sportspress_' . $key . '_slug', null ); + ?>
    + not using "default" permalinks above.', 'sportspress' ) ); + } + + /** + * Save the settings + */ + public function settings_save() { + if ( ! is_admin() ) { + return; + } + + if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['sportspress_event_slug'] ) ) : + foreach ( $this->slugs as $slug ) : + $key = 'sportspress_' . $slug[0] . '_slug'; + $value = null; + if ( isset( $_POST[ $key ] ) ) { + $value = sanitize_text_field( $_POST[ $key ] ); + } + if ( empty( $value ) ) { + delete_option( $key ); + } else { + update_option( $key, $value ); + } + endforeach; + sp_flush_rewrite_rules(); + endif; + } } -} endif; -return new SP_Admin_Permalink_Settings(); \ No newline at end of file +return new SP_Admin_Permalink_Settings(); diff --git a/includes/admin/class-sp-admin-post-types.php b/includes/admin/class-sp-admin-post-types.php index b8abe5fe..8304537c 100644 --- a/includes/admin/class-sp-admin-post-types.php +++ b/includes/admin/class-sp-admin-post-types.php @@ -2,122 +2,126 @@ /** * Post Types Admin * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin * @version 2.0 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Post_Types' ) ) : -/** - * SP_Admin_Post_Types Class - */ -class SP_Admin_Post_Types { - /** - * Constructor + * SP_Admin_Post_Types Class */ - public function __construct() { - add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) ); - add_action( 'save_post', array( $this, 'unflag_post' ) ); - add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); - add_filter( 'sportspress_meta_boxes', array( $this, 'meta_boxes' ) ); - } + class SP_Admin_Post_Types { - /** - * Conditonally load classes and functions only needed when viewing a post type. - */ - public function include_post_type_handlers() { - include_once( 'post-types/class-sp-admin-meta-boxes.php' ); - include_once( 'post-types/class-sp-admin-cpt-result.php' ); - include_once( 'post-types/class-sp-admin-cpt-outcome.php' ); - include_once( 'post-types/class-sp-admin-cpt-performance.php' ); - include_once( 'post-types/class-sp-admin-cpt-column.php' ); - include_once( 'post-types/class-sp-admin-cpt-metric.php' ); - include_once( 'post-types/class-sp-admin-cpt-statistic.php' ); - include_once( 'post-types/class-sp-admin-cpt-event.php' ); - include_once( 'post-types/class-sp-admin-cpt-team.php' ); - include_once( 'post-types/class-sp-admin-cpt-player.php' ); - include_once( 'post-types/class-sp-admin-cpt-staff.php' ); - do_action( 'sportspress_include_post_type_handlers' ); - } + /** + * Constructor + */ + public function __construct() { + add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) ); + add_action( 'save_post', array( $this, 'unflag_post' ) ); + add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); + add_filter( 'sportspress_meta_boxes', array( $this, 'meta_boxes' ) ); + } - /** - * Unflag preset and sample posts. - */ - public function unflag_post( $post_id ) { - $post_types = sp_post_types(); - $config_types = sp_config_types(); - $post_type = get_post_type( $post_id ); - if ( in_array( $post_type, $post_types ) ): - delete_post_meta( $post_id, '_sp_sample' ); - elseif ( in_array( $post_type, $config_types ) ): - delete_post_meta( $post_id, '_sp_preset' ); - endif; - } + /** + * Conditonally load classes and functions only needed when viewing a post type. + */ + public function include_post_type_handlers() { + include_once 'post-types/class-sp-admin-meta-boxes.php'; + include_once 'post-types/class-sp-admin-cpt-result.php'; + include_once 'post-types/class-sp-admin-cpt-outcome.php'; + include_once 'post-types/class-sp-admin-cpt-performance.php'; + include_once 'post-types/class-sp-admin-cpt-column.php'; + include_once 'post-types/class-sp-admin-cpt-metric.php'; + include_once 'post-types/class-sp-admin-cpt-statistic.php'; + include_once 'post-types/class-sp-admin-cpt-event.php'; + include_once 'post-types/class-sp-admin-cpt-team.php'; + include_once 'post-types/class-sp-admin-cpt-player.php'; + include_once 'post-types/class-sp-admin-cpt-staff.php'; + do_action( 'sportspress_include_post_type_handlers' ); + } - /** - * Change messages when a post type is updated. - * - * @param array $messages - * @return array - */ - public function post_updated_messages( $messages ) { - global $typenow, $post; + /** + * Unflag preset and sample posts. + */ + public function unflag_post( $post_id ) { + $post_types = sp_post_types(); + $config_types = sp_config_types(); + $post_type = get_post_type( $post_id ); + if ( in_array( $post_type, $post_types ) ) : + delete_post_meta( $post_id, '_sp_sample' ); + elseif ( in_array( $post_type, $config_types ) ) : + delete_post_meta( $post_id, '_sp_preset' ); + endif; + } - if ( is_sp_config_type( $typenow ) ): - $obj = get_post_type_object( $typenow ); + /** + * Change messages when a post type is updated. + * + * @param array $messages + * @return array + */ + public function post_updated_messages( $messages ) { + global $typenow, $post; - for ( $i = 0; $i <= 10; $i++ ): - $messages['post'][ $i ] = __( 'Settings saved.', 'sportspress' ) . + if ( is_sp_config_type( $typenow ) ) : + $obj = get_post_type_object( $typenow ); + + for ( $i = 0; $i <= 10; $i++ ) : + $messages['post'][ $i ] = __( 'Settings saved.', 'sportspress' ) . ' ' . __( 'View All', 'sportspress' ) . ''; - endfor; - elseif ( is_sp_post_type( $typenow ) ): - $obj = get_post_type_object( $typenow ); + endfor; + elseif ( is_sp_post_type( $typenow ) ) : + $obj = get_post_type_object( $typenow ); - $messages['post'][1] = __( 'Changes saved.', 'sportspress' ) . - ' ' . $obj->labels->view_item . ''; + $messages['post'][1] = __( 'Changes saved.', 'sportspress' ) . + ' ' . $obj->labels->view_item . ''; - $messages['post'][4] = __( 'Changes saved.', 'sportspress' ); + $messages['post'][4] = __( 'Changes saved.', 'sportspress' ); - $messages['post'][6] = __( 'Success!', 'sportspress' ) . - ' ' . $obj->labels->view_item . ''; + $messages['post'][6] = __( 'Success!', 'sportspress' ) . + ' ' . $obj->labels->view_item . ''; - $messages['post'][7] = __( 'Changes saved.', 'sportspress' ); + $messages['post'][7] = __( 'Changes saved.', 'sportspress' ); - $messages['post'][8] = __( 'Success!', 'sportspress' ) . - ' ' . + $messages['post'][8] = __( 'Success!', 'sportspress' ) . + ' ' . sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . ''; - $messages['post'][9] = sprintf( - __( 'Scheduled for: %1$s.', 'sportspress' ), - date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post->ID) ) ) . - ' ' . - sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . ''; + $messages['post'][9] = sprintf( + __( 'Scheduled for: %1$s.', 'sportspress' ), + date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ), + esc_url( get_permalink( $post->ID ) ) + ) . + ' ' . + sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . ''; - $messages['post'][10] = __( 'Success!', 'sportspress' ) . - ' ' . - sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . ''; - endif; + $messages['post'][10] = __( 'Success!', 'sportspress' ) . + ' ' . + sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . ''; + endif; - return $messages; - } - - /** - * Remove meta boxes as needed - */ - public static function meta_boxes( $meta_boxes ) { - if ( 'manual' != get_option( 'sportspress_player_columns', 'auto' ) ) { - unset( $meta_boxes['sp_player']['columns'] ); + return $messages; + } + + /** + * Remove meta boxes as needed + */ + public static function meta_boxes( $meta_boxes ) { + if ( 'manual' != get_option( 'sportspress_player_columns', 'auto' ) ) { + unset( $meta_boxes['sp_player']['columns'] ); + } + return $meta_boxes; } - return $meta_boxes; } -} endif; -return new SP_Admin_Post_Types(); \ No newline at end of file +return new SP_Admin_Post_Types(); diff --git a/includes/admin/class-sp-admin-sample-data.php b/includes/admin/class-sp-admin-sample-data.php index 768001a1..060118c4 100644 --- a/includes/admin/class-sp-admin-sample-data.php +++ b/includes/admin/class-sp-admin-sample-data.php @@ -4,11 +4,11 @@ * * The SportsPress admin sample data class stores demo content. * - * @class SP_Admin_Sample_Data - * @version 2.5 - * @package SportsPress/Admin - * @category Class - * @author ThemeBoy + * @class SP_Admin_Sample_Data + * @version 2.5 + * @package SportsPress/Admin + * @category Class + * @author ThemeBoy */ class SP_Admin_Sample_Data { @@ -23,18 +23,18 @@ class SP_Admin_Sample_Data { // Initialize inserted ids array $inserted_ids = array( - 'sp_league' => array(), - 'sp_season' => array(), - 'sp_venue' => array(), + 'sp_league' => array(), + 'sp_season' => array(), + 'sp_venue' => array(), 'sp_position' => array(), - 'sp_role' => array(), - 'sp_event' => array(), + 'sp_role' => array(), + 'sp_event' => array(), 'sp_calendar' => array(), - 'sp_team' => array(), - 'sp_table' => array(), - 'sp_player' => array(), - 'sp_list' => array(), - 'sp_staff' => array(), + 'sp_team' => array(), + 'sp_table' => array(), + 'sp_player' => array(), + 'sp_list' => array(), + 'sp_staff' => array(), ); // Terms to insert @@ -44,33 +44,33 @@ class SP_Admin_Sample_Data { $taxonomies['sp_league'] = array( _x( 'Primary League', 'example', 'sportspress' ), _x( 'Secondary League', 'example', 'sportspress' ) ); // Seasons - $current_year = date( 'Y' ); - $current_year = intval( $current_year ); + $current_year = date( 'Y' ); + $current_year = intval( $current_year ); $taxonomies['sp_season'] = array( $current_year - 1, $current_year, $current_year + 1 ); // Venues - $taxonomies['sp_venue'] = array( + $taxonomies['sp_venue'] = array( array( 'name' => 'Bentleigh', 'meta' => array( - 'sp_address' => '12A Bolinda Street, Bentleigh VIC 3204, Australia', - 'sp_latitude' => -37.920537, + 'sp_address' => '12A Bolinda Street, Bentleigh VIC 3204, Australia', + 'sp_latitude' => -37.920537, 'sp_longitude' => 145.043199, ), ), array( 'name' => 'Essendon', 'meta' => array( - 'sp_address' => '74 Napier Street, Essendon VIC 3040, Australia', - 'sp_latitude' => -37.751940, + 'sp_address' => '74 Napier Street, Essendon VIC 3040, Australia', + 'sp_latitude' => -37.751940, 'sp_longitude' => 144.919549, ), ), array( 'name' => 'Kensington', 'meta' => array( - 'sp_address' => '50 Altona Street, Kensington, Victoria, Australia', - 'sp_latitude' => -37.797789, + 'sp_address' => '50 Altona Street, Kensington, Victoria, Australia', + 'sp_latitude' => -37.797789, 'sp_longitude' => 144.924709, ), ), @@ -92,14 +92,21 @@ class SP_Admin_Sample_Data { } // Insert term - $inserted = wp_insert_term( $name, $taxonomy, array( 'description' => $name, 'slug' => sanitize_title( $name ) ) ); + $inserted = wp_insert_term( + $name, + $taxonomy, + array( + 'description' => $name, + 'slug' => sanitize_title( $name ), + ) + ); // Add meta to term if is array if ( ! is_wp_error( $inserted ) && is_array( $term ) && array_key_exists( 'meta', $term ) ) { $t_id = sp_array_value( $inserted, 'term_id', 1 ); $meta = sp_array_value( $term, 'meta' ); update_option( "taxonomy_$t_id", $meta ); - + // Add to inserted ids array $inserted_ids[ $taxonomy ][] = $t_id; } @@ -113,15 +120,15 @@ class SP_Admin_Sample_Data { $teams = array( array( 'name' => 'Bluebirds', - 'url' => 'http://tboy.co/bluebirds', + 'url' => 'http://tboy.co/bluebirds', ), array( 'name' => 'Eagles', - 'url' => 'http://tboy.co/eagles', + 'url' => 'http://tboy.co/eagles', ), array( 'name' => 'Kangaroos', - 'url' => 'http://tboy.co/kangaroos', + 'url' => 'http://tboy.co/kangaroos', ), ); @@ -160,19 +167,35 @@ class SP_Admin_Sample_Data { * Insert teams */ foreach ( $teams as $index => $team ) { - $post['post_title'] = $team['name']; - $post['post_type'] = 'sp_team'; - $post['post_status'] = 'publish'; + $post['post_title'] = $team['name']; + $post['post_type'] = 'sp_team'; + $post['post_status'] = 'publish'; $post['post_content'] = sprintf( $sample_content, __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), add_query_arg( 'post_type', 'sp_team', admin_url( 'edit.php' ) ) ); // Terms $post['tax_input'] = array(); - $taxonomies = array( 'sp_league', 'sp_season' ); + $taxonomies = array( 'sp_league', 'sp_season' ); foreach ( $taxonomies as $taxonomy ) { - $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); - }; + $post['tax_input'][ $taxonomy ] = get_terms( + $taxonomy, + array( + 'hide_empty' => 0, + 'fields' => 'ids', + ) + ); + } - $post['tax_input']['sp_venue'] = get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $index ) ); + $post['tax_input']['sp_venue'] = get_terms( + 'sp_venue', + array( + 'hide_empty' => 0, + 'fields' => 'ids', + 'orderby' => 'id', + 'order' => 'ASC', + 'number' => 1, + 'offset' => $index, + ) + ); // Insert post $id = wp_insert_post( $post ); @@ -189,13 +212,13 @@ class SP_Admin_Sample_Data { // Get columns $columns = array( 'team' ); - $args = array( - 'post_type' => array( 'sp_performance', 'sp_statistic' ), + $args = array( + 'post_type' => array( 'sp_performance', 'sp_statistic' ), 'posts_per_page' => 2, - 'orderby' => 'menu_order', - 'order' => 'ASC', + 'orderby' => 'menu_order', + 'order' => 'ASC', ); - $vars = get_posts( $args ); + $vars = get_posts( $args ); foreach ( $vars as $var ) { $columns[] = $var->post_name; } @@ -204,24 +227,39 @@ class SP_Admin_Sample_Data { * Insert players */ foreach ( $players as $index => $name ) { - $post['post_title'] = $name; - $post['post_type'] = 'sp_player'; - $post['post_status'] = 'publish'; + $post['post_title'] = $name; + $post['post_type'] = 'sp_player'; + $post['post_status'] = 'publish'; $post['post_content'] = sprintf( $sample_content, __( 'Player', 'sportspress' ), __( 'Players', 'sportspress' ), add_query_arg( 'post_type', 'sp_player', admin_url( 'edit.php' ) ) ); // Terms $post['tax_input'] = array(); - $taxonomies = array( 'sp_league', 'sp_season' ); + $taxonomies = array( 'sp_league', 'sp_season' ); foreach ( $taxonomies as $taxonomy ) { - $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); - }; + $post['tax_input'][ $taxonomy ] = get_terms( + $taxonomy, + array( + 'hide_empty' => 0, + 'fields' => 'ids', + ) + ); + } $taxonomies = array( 'sp_position' ); foreach ( $taxonomies as $taxonomy ) { - $terms = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'slug', 'number' => 1, 'offset' => $index % 4 ) ); + $terms = get_terms( + $taxonomy, + array( + 'hide_empty' => 0, + 'fields' => 'ids', + 'orderby' => 'slug', + 'number' => 1, + 'offset' => $index % 4, + ) + ); if ( $terms && ! is_wp_error( $terms ) ) { $post['tax_input'][ $taxonomy ] = $terms; } - }; + } // Insert post $id = wp_insert_post( $post ); @@ -233,13 +271,13 @@ class SP_Admin_Sample_Data { update_post_meta( $id, '_sp_sample', 1 ); // Calculate meta - $nationality = array_rand( $countries->countries ); - $team_index = floor( $index / 4 ); + $nationality = array_rand( $countries->countries ); + $team_index = floor( $index / 4 ); $past_team_index = ( $team_index + 1 ) % 3; - $current_team = sp_array_value( $inserted_ids['sp_team'], $team_index, 0 ); - $past_team = sp_array_value( $inserted_ids['sp_team'], $past_team_index, 0 ); - $primary_league = reset( $post['tax_input']['sp_league'] ); - $season_teams = $season_stats = array(); + $current_team = sp_array_value( $inserted_ids['sp_team'], $team_index, 0 ); + $past_team = sp_array_value( $inserted_ids['sp_team'], $past_team_index, 0 ); + $primary_league = reset( $post['tax_input']['sp_league'] ); + $season_teams = $season_stats = array(); foreach ( $post['tax_input']['sp_season'] as $season_index => $season_id ) { $season_stats[ $season_id ] = array(); if ( $season_index == 0 ) { @@ -253,7 +291,7 @@ class SP_Admin_Sample_Data { } } } - $player_stats = array( $primary_league => $season_stats ); + $player_stats = array( $primary_league => $season_stats ); $player_leagues = array( $primary_league => $season_teams ); // Update meta @@ -268,30 +306,32 @@ class SP_Admin_Sample_Data { } // Get columns - $columns = array(); - $args = array( - 'post_type' => 'sp_performance', + $columns = array(); + $args = array( + 'post_type' => 'sp_performance', 'posts_per_page' => -1, - 'orderby' => 'menu_order', - 'order' => 'ASC', + 'orderby' => 'menu_order', + 'order' => 'ASC', ); $performance_posts = get_posts( $args ); foreach ( $performance_posts as $performance_post ) { - if ( sizeof( $columns ) >= 5 ) continue; + if ( sizeof( $columns ) >= 5 ) { + continue; + } $columns[] = $performance_post->post_name; } - $args = array( - 'post_type' => 'sp_result', + $args = array( + 'post_type' => 'sp_result', 'posts_per_page' => -1, - 'orderby' => 'menu_order', - 'order' => 'ASC', + 'orderby' => 'menu_order', + 'order' => 'ASC', ); - $result_posts = get_posts( $args ); - $args = array( - 'post_type' => 'sp_outcome', + $result_posts = get_posts( $args ); + $args = array( + 'post_type' => 'sp_outcome', 'posts_per_page' => -1, - 'orderby' => 'menu_order', - 'order' => 'ASC', + 'orderby' => 'menu_order', + 'order' => 'ASC', ); $outcome_posts = get_posts( $args ); @@ -299,22 +339,37 @@ class SP_Admin_Sample_Data { * Insert staff */ foreach ( $staff as $index => $name ) { - $post['post_title'] = $name; - $post['post_type'] = 'sp_staff'; - $post['post_status'] = 'publish'; + $post['post_title'] = $name; + $post['post_type'] = 'sp_staff'; + $post['post_status'] = 'publish'; $post['post_content'] = sprintf( $sample_content, __( 'Staff', 'sportspress' ), __( 'Staff', 'sportspress' ), add_query_arg( 'post_type', 'sp_staff', admin_url( 'edit.php' ) ) ); // Terms $post['tax_input'] = array(); - $taxonomies = array( 'sp_league', 'sp_season' ); + $taxonomies = array( 'sp_league', 'sp_season' ); foreach ( $taxonomies as $taxonomy ) { - $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); - }; + $post['tax_input'][ $taxonomy ] = get_terms( + $taxonomy, + array( + 'hide_empty' => 0, + 'fields' => 'ids', + ) + ); + } $taxonomies = array( 'sp_role' ); foreach ( $taxonomies as $taxonomy ) { - $terms = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'slug', 'number' => 1, 'offset' => $index % 4 ) ); + $terms = get_terms( + $taxonomy, + array( + 'hide_empty' => 0, + 'fields' => 'ids', + 'orderby' => 'slug', + 'number' => 1, + 'offset' => $index % 4, + ) + ); $post['tax_input'][ $taxonomy ] = $terms; - }; + } // Insert post $id = wp_insert_post( $post ); @@ -326,8 +381,8 @@ class SP_Admin_Sample_Data { update_post_meta( $id, '_sp_sample', 1 ); // Calculate meta - $team_index = floor( $index / 4 ); - $past_teams = $inserted_ids['sp_team']; + $team_index = floor( $index / 4 ); + $past_teams = $inserted_ids['sp_team']; $current_team = sp_array_value( $past_teams, $team_index, 0 ); unset( $past_teams[ $team_index ] ); @@ -347,27 +402,67 @@ class SP_Admin_Sample_Data { // Determine team index and post status $i = $index % 3; if ( $index < 3 ) { - $post_status = 'publish'; - $post_year = $current_year - 1; - $event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); + $post_status = 'publish'; + $post_year = $current_year - 1; + $event_season = get_terms( + 'sp_season', + array( + 'hide_empty' => 0, + 'fields' => 'ids', + 'orderby' => 'id', + 'order' => 'ASC', + 'number' => 1, + ) + ); } else { - $post_status = 'future'; - $post_year = $current_year + 1; - $event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'DESC', 'number' => 1 ) ); + $post_status = 'future'; + $post_year = $current_year + 1; + $event_season = get_terms( + 'sp_season', + array( + 'hide_empty' => 0, + 'fields' => 'ids', + 'orderby' => 'id', + 'order' => 'DESC', + 'number' => 1, + ) + ); } // The away team should be the next inserted team, or the first if this is the last event - if ( $i == 2 ) $away_index = 0; - else $away_index = $i + 1; + if ( $i == 2 ) { + $away_index = 0; + } else { + $away_index = $i + 1; + } $post = array( - 'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'], - 'post_type' => 'sp_event', - 'post_status' => $post_status, + 'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'], + 'post_type' => 'sp_event', + 'post_status' => $post_status, 'post_content' => sprintf( $sample_content, __( 'Event', 'sportspress' ), __( 'Events', 'sportspress' ), add_query_arg( 'post_type', 'sp_event', admin_url( 'edit.php' ) ) ), - 'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00', - 'tax_input' => array( - 'sp_league' => get_terms( 'sp_league', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ), + 'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00', + 'tax_input' => array( + 'sp_league' => get_terms( + 'sp_league', + array( + 'hide_empty' => 0, + 'fields' => 'ids', + 'orderby' => 'id', + 'order' => 'ASC', + 'number' => 1, + ) + ), 'sp_season' => $event_season, - 'sp_venue' => get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $i ) ), + 'sp_venue' => get_terms( + 'sp_venue', + array( + 'hide_empty' => 0, + 'fields' => 'ids', + 'orderby' => 'id', + 'order' => 'ASC', + 'number' => 1, + 'offset' => $i, + ) + ), ), ); @@ -383,23 +478,23 @@ class SP_Admin_Sample_Data { // Calculate home and away team ids $home_team_index = ( $i ) % 3; $away_team_index = ( $i + 1 ) % 3; - $home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 ); - $away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 ); - $event_teams = array( + $home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 ); + $away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 ); + $event_teams = array( $home_team_id, $away_team_id, ); // Initialize meta $event_players = array( 0 ); - $performance = $results = array(); + $performance = $results = array(); if ( $home_team_id ) { // Add home team player performance $performance[ $home_team_id ] = array(); for ( $j = 0; $j < 4; $j ++ ) { - $player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j ); - $event_players[] = $player_id; + $player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j ); + $event_players[] = $player_id; $player_performance = array(); foreach ( $performance_posts as $performance_post ) { $player_performance[ $performance_post->post_name ] = rand( 0, 1 ); @@ -413,7 +508,9 @@ class SP_Admin_Sample_Data { $results[ $home_team_id ][ $result_post->post_name ] = 1 + $result_post_index; } $outcome = reset( $outcome_posts ); - if ( is_object( $outcome ) ) $results[ $home_team_id ]['outcome'] = array( $outcome->post_name ); + if ( is_object( $outcome ) ) { + $results[ $home_team_id ]['outcome'] = array( $outcome->post_name ); + } } // Separate teams with zero @@ -422,8 +519,8 @@ class SP_Admin_Sample_Data { if ( $away_team_id ) { $performance[ $away_team_id ] = array(); for ( $j = 0; $j < 4; $j ++ ) { - $player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j ); - $event_players[] = $player_id; + $player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j ); + $event_players[] = $player_id; $player_performance = array(); foreach ( $performance_posts as $performance_post ) { $player_performance[ $performance_post->post_name ] = rand( 0, 1 ); @@ -437,15 +534,17 @@ class SP_Admin_Sample_Data { $results[ $away_team_id ][ $result_post->post_name ] = '0'; } $outcome = next( $outcome_posts ); - if ( is_object( $outcome ) ) $results[ $away_team_id ]['outcome'] = array( $outcome->post_name ); + if ( is_object( $outcome ) ) { + $results[ $away_team_id ]['outcome'] = array( $outcome->post_name ); + } } if ( 'publish' === $post_status ) { // Swap results for last event only if ( $i == 2 ) { - $k = array_keys( $results ); - $v = array_values( $results ); - $rv = array_reverse( $v ); + $k = array_keys( $results ); + $v = array_values( $results ); + $rv = array_reverse( $v ); $results = array_combine( $k, $rv ); } @@ -466,10 +565,10 @@ class SP_Admin_Sample_Data { * Insert calendar */ $post = array( - 'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ), - 'post_type' => 'sp_calendar', - 'post_status' => 'publish', - 'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), add_query_arg( 'post_type', 'sp_calendar', admin_url( 'edit.php' ) ) ) + 'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ), + 'post_type' => 'sp_calendar', + 'post_status' => 'publish', + 'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), add_query_arg( 'post_type', 'sp_calendar', admin_url( 'edit.php' ) ) ), ); // Insert post @@ -495,16 +594,32 @@ class SP_Admin_Sample_Data { /* * Insert league table */ - $leagues = get_terms( 'sp_league', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); - $league = reset( $leagues ); - $seasons = get_terms( 'sp_season', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); - $season = reset( $seasons ); - $post = array( - 'post_title' => $league->name . ' ' . $season->name, - 'post_type' => 'sp_table', - 'post_status' => 'publish', + $leagues = get_terms( + 'sp_league', + array( + 'hide_empty' => 0, + 'orderby' => 'id', + 'order' => 'ASC', + 'number' => 1, + ) + ); + $league = reset( $leagues ); + $seasons = get_terms( + 'sp_season', + array( + 'hide_empty' => 0, + 'orderby' => 'id', + 'order' => 'ASC', + 'number' => 1, + ) + ); + $season = reset( $seasons ); + $post = array( + 'post_title' => $league->name . ' ' . $season->name, + 'post_type' => 'sp_table', + 'post_status' => 'publish', 'post_content' => sprintf( $sample_content, __( 'League Table', 'sportspress' ), __( 'League Tables', 'sportspress' ), add_query_arg( 'post_type', 'sp_table', admin_url( 'edit.php' ) ) ), - 'tax_input' => array( + 'tax_input' => array( 'sp_league' => $league->term_id, 'sp_season' => $season->term_id, ), @@ -520,12 +635,12 @@ class SP_Admin_Sample_Data { update_post_meta( $id, '_sp_sample', 1 ); // Get columns - $columns = array(); - $args = array( - 'post_type' => 'sp_column', + $columns = array(); + $args = array( + 'post_type' => 'sp_column', 'posts_per_page' => 8, - 'orderby' => 'menu_order', - 'order' => 'ASC', + 'orderby' => 'menu_order', + 'order' => 'ASC', ); $column_posts = get_posts( $args ); foreach ( $column_posts as $column_post ) { @@ -542,9 +657,9 @@ class SP_Admin_Sample_Data { */ foreach ( $inserted_ids['sp_team'] as $index => $team_id ) { $post = array( - 'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ), - 'post_type' => 'sp_list', - 'post_status' => 'publish', + 'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ), + 'post_type' => 'sp_list', + 'post_status' => 'publish', 'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), add_query_arg( 'post_type', 'sp_list', admin_url( 'edit.php' ) ) ), ); @@ -561,12 +676,12 @@ class SP_Admin_Sample_Data { $list_players = array_slice( $inserted_ids['sp_player'], $index * 4, 4 ); // Get columns - $columns = array(); - $args = array( - 'post_type' => array( 'sp_metric' ), + $columns = array(); + $args = array( + 'post_type' => array( 'sp_metric' ), 'posts_per_page' => 2, - 'orderby' => 'menu_order', - 'order' => 'ASC', + 'orderby' => 'menu_order', + 'order' => 'ASC', ); $column_posts = get_posts( $args ); foreach ( $column_posts as $column_post ) { @@ -587,9 +702,9 @@ class SP_Admin_Sample_Data { * Insert player list for player ranking */ $post = array( - 'post_title' => _x( 'Player Ranking', 'example', 'sportspress' ), - 'post_type' => 'sp_list', - 'post_status' => 'publish', + 'post_title' => _x( 'Player Ranking', 'example', 'sportspress' ), + 'post_type' => 'sp_list', + 'post_status' => 'publish', 'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), add_query_arg( 'post_type', 'sp_list', admin_url( 'edit.php' ) ) ), ); @@ -603,9 +718,11 @@ class SP_Admin_Sample_Data { update_post_meta( $id, '_sp_sample', 1 ); // Get columns - $columns = array( 'team' ); + $columns = array( 'team' ); $performance_post = reset( $performance_posts ); - if ( is_object( $performance_post ) ) $columns[] = $performance_post->post_name; + if ( is_object( $performance_post ) ) { + $columns[] = $performance_post->post_name; + } // Update meta update_post_meta( $id, 'sp_format', 'list' ); @@ -613,7 +730,9 @@ class SP_Admin_Sample_Data { update_post_meta( $id, 'sp_columns', $columns ); update_post_meta( $id, 'sp_grouping', '0' ); update_post_meta( $id, 'sp_order', 'DESC' ); - if ( is_object( $performance_post ) ) update_post_meta( $id, 'sp_orderby', $performance_post->post_name ); + if ( is_object( $performance_post ) ) { + update_post_meta( $id, 'sp_orderby', $performance_post->post_name ); + } /* * Update player list and league table per team @@ -631,21 +750,21 @@ class SP_Admin_Sample_Data { */ public static function delete_posts() { $post_types = sp_post_types(); - $args = array( - 'post_type' => $post_types, + $args = array( + 'post_type' => $post_types, 'posts_per_page' => -1, - 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), - 'meta_query' => array( + 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), + 'meta_query' => array( array( - 'key' => '_sp_sample', - 'value' => 1 - ) + 'key' => '_sp_sample', + 'value' => 1, + ), ), ); // Delete posts $old_posts = get_posts( $args ); - foreach( $old_posts as $post ): + foreach ( $old_posts as $post ) : wp_delete_post( $post->ID, true ); endforeach; } diff --git a/includes/admin/class-sp-admin-settings.php b/includes/admin/class-sp-admin-settings.php index 362eb141..4cae50d2 100644 --- a/includes/admin/class-sp-admin-settings.php +++ b/includes/admin/class-sp-admin-settings.php @@ -8,480 +8,568 @@ * @version 2.7.9 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Settings' ) ) : -/** - * SP_Admin_Settings - */ -class SP_Admin_Settings { - - private static $settings = array(); - private static $errors = array(); - private static $messages = array(); - private static $overrides = array(); - /** - * Include the settings page classes + * SP_Admin_Settings */ - public static function get_settings_pages() { - if ( empty( self::$settings ) ) { - $settings = array(); + class SP_Admin_Settings { - include_once( 'class-sp-admin-sports.php' ); - include_once( 'settings/class-sp-settings-page.php' ); + private static $settings = array(); + private static $errors = array(); + private static $messages = array(); + private static $overrides = array(); - $settings[] = include( 'settings/class-sp-settings-modules.php' ); - $settings[] = include( 'settings/class-sp-settings-general.php' ); - $settings[] = include( 'settings/class-sp-settings-events.php' ); - $settings[] = include( 'settings/class-sp-settings-teams.php' ); - $settings[] = include( 'settings/class-sp-settings-players.php' ); - $settings[] = include( 'settings/class-sp-settings-staff.php' ); + /** + * Include the settings page classes + */ + public static function get_settings_pages() { + if ( empty( self::$settings ) ) { + $settings = array(); - $settings = apply_filters( 'sportspress_get_settings_pages', $settings ); + include_once 'class-sp-admin-sports.php'; + include_once 'settings/class-sp-settings-page.php'; - $settings[] = include( 'settings/class-sp-settings-text.php' ); + $settings[] = include 'settings/class-sp-settings-modules.php'; + $settings[] = include 'settings/class-sp-settings-general.php'; + $settings[] = include 'settings/class-sp-settings-events.php'; + $settings[] = include 'settings/class-sp-settings-teams.php'; + $settings[] = include 'settings/class-sp-settings-players.php'; + $settings[] = include 'settings/class-sp-settings-staff.php'; - if ( + $settings = apply_filters( 'sportspress_get_settings_pages', $settings ); + + $settings[] = include 'settings/class-sp-settings-text.php'; + + if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || ( is_multisite() && current_user_can( 'manage_network_options' ) ) - ) { - $settings[] = include( 'settings/class-sp-settings-licenses.php' ); + ) { + $settings[] = include 'settings/class-sp-settings-licenses.php'; + } + + $settings[] = include 'settings/class-sp-settings-status.php'; + + self::$settings = apply_filters( 'sportspress_get_settings_config_pages', $settings ); } - - $settings[] = include( 'settings/class-sp-settings-status.php' ); - - self::$settings = apply_filters( 'sportspress_get_settings_config_pages', $settings ); - } - return self::$settings; - } - - /** - * Save the settings - */ - public static function save() { - global $current_section, $current_tab; - - if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'sportspress-settings' ) ) - die( __( 'Action failed. Please refresh the page and retry.', 'sportspress' ) ); - - // Trigger actions - do_action( 'sportspress_settings_save_' . $current_tab ); - do_action( 'sportspress_update_options_' . $current_tab ); - do_action( 'sportspress_update_options' ); - - self::add_message( __( 'Your settings have been saved.', 'sportspress' ) ); - - do_action( 'sportspress_settings_saved' ); - } - - /** - * Add a message - * @param string $text - */ - public static function add_message( $text ) { - self::$messages[] = $text; - } - - /** - * Add an override - * @param string $text - */ - public static function add_override( $text ) { - self::$overrides[] = $text; - } - - /** - * Add an error - * @param string $text - */ - public static function add_error( $text ) { - self::$errors[] = $text; - } - - /** - * Output messages + overrides + errors - */ - public static function show_messages() { - if ( sizeof( self::$errors ) > 0 ) { - foreach ( self::$errors as $error ) - echo '

    ' . esc_html( $error ) . '

    '; - } elseif ( sizeof( self::$overrides ) > 0 ) { - foreach ( self::$overrides as $override ) - echo '

    ' . esc_html( $override ) . '

    '; - } elseif ( sizeof( self::$messages ) > 0 ) { - foreach ( self::$messages as $message ) - echo '

    ' . esc_html( $message ) . '

    '; - } - } - - /** - * Settings page. - * - * Handles the display of the main sportspress settings page in admin. - * - * @access public - * @return void - */ - public static function output() { - global $current_section, $current_tab; - - do_action( 'sportspress_settings_start' ); - - wp_enqueue_script( 'sportspress_settings', SP()->plugin_url() . '/assets/js/admin/settings.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'chosen' ), SP()->version, true ); - - wp_localize_script( 'sportspress_settings', 'localized_strings', array( - 'none' => __( 'None', 'sportspress' ) - ) ); - - // Include settings pages - self::get_settings_pages(); - - // Get current tab/section - $current_tab = empty( $_GET['tab'] ) ? 'modules' : sanitize_title( $_GET['tab'] ); - $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] ); - - // Save settings if data has been posted - if ( ! empty( $_POST ) ) - self::save(); - - // Add any posted messages - if ( ! empty( $_GET['sp_error'] ) ) - self::add_error( stripslashes( $_GET['sp_error'] ) ); - - if ( ! empty( $_GET['sp_message'] ) ) - self::add_message( stripslashes( $_GET['sp_message'] ) ); - - self::show_messages(); - - // Get tabs for the settings page - $tabs = apply_filters( 'sportspress_settings_tabs_array', array() ); - - include 'views/html-admin-settings.php'; - } - - /** - * Get a setting from the settings API. - * - * @param mixed $option - * @return string - */ - public static function get_option( $option_name, $default = '' ) { - // Array value - if ( strstr( $option_name, '[' ) ) { - - parse_str( html_entity_decode( $option_name ), $option_array ); - - // Option name is first key - $option_name = current( array_keys( $option_array ) ); - - // Get value - $option_values = get_option( $option_name, '' ); - - $key = key( $option_array[ $option_name ] ); - - if ( isset( $option_values[ $key ] ) ) - $option_value = $option_values[ $key ]; - else - $option_value = null; - - // Single value - } else { - $option_value = get_option( $option_name, null ); + return self::$settings; } - if ( is_array( $option_value ) ) - $option_value = array_map( 'stripslashes', $option_value ); - elseif ( ! is_null( $option_value ) ) - $option_value = stripslashes( $option_value ); + /** + * Save the settings + */ + public static function save() { + global $current_section, $current_tab; - return $option_value === null ? $default : $option_value; - } + if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'sportspress-settings' ) ) { + die( __( 'Action failed. Please refresh the page and retry.', 'sportspress' ) ); + } - /** - * Output admin fields. - * - * Loops though the sportspress options array and outputs each field. - * - * @access public - * @param array $options Opens array to output - */ - public static function output_fields( $options ) { - foreach ( $options as $value ) { - if ( ! isset( $value['type'] ) ) continue; - if ( ! isset( $value['id'] ) ) $value['id'] = ''; - if ( ! isset( $value['title'] ) ) $value['title'] = isset( $value['name'] ) ? $value['name'] : ''; - if ( ! isset( $value['class'] ) ) $value['class'] = ''; - if ( ! isset( $value['css'] ) ) $value['css'] = ''; - if ( ! isset( $value['default'] ) ) $value['default'] = ''; - if ( ! isset( $value['desc'] ) ) $value['desc'] = ''; - if ( ! isset( $value['desc_tip'] ) ) $value['desc_tip'] = false; - if ( ! isset( $value['placeholder'] ) ) $value['placeholder'] = ''; + // Trigger actions + do_action( 'sportspress_settings_save_' . $current_tab ); + do_action( 'sportspress_update_options_' . $current_tab ); + do_action( 'sportspress_update_options' ); - // Custom attribute handling - $custom_attributes = array(); + self::add_message( __( 'Your settings have been saved.', 'sportspress' ) ); - if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) - foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) - $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; + do_action( 'sportspress_settings_saved' ); + } - // Description handling - if ( $value['desc_tip'] === true ) { - $description = ''; - $tip = $value['desc']; - } elseif ( ! empty( $value['desc_tip'] ) ) { - $description = $value['desc']; - $tip = $value['desc_tip']; - } elseif ( ! empty( $value['desc'] ) ) { - $description = $value['desc']; - $tip = ''; + /** + * Add a message + * + * @param string $text + */ + public static function add_message( $text ) { + self::$messages[] = $text; + } + + /** + * Add an override + * + * @param string $text + */ + public static function add_override( $text ) { + self::$overrides[] = $text; + } + + /** + * Add an error + * + * @param string $text + */ + public static function add_error( $text ) { + self::$errors[] = $text; + } + + /** + * Output messages + overrides + errors + */ + public static function show_messages() { + if ( sizeof( self::$errors ) > 0 ) { + foreach ( self::$errors as $error ) { + echo '

    ' . esc_html( $error ) . '

    '; + } + } elseif ( sizeof( self::$overrides ) > 0 ) { + foreach ( self::$overrides as $override ) { + echo '

    ' . esc_html( $override ) . '

    '; + } + } elseif ( sizeof( self::$messages ) > 0 ) { + foreach ( self::$messages as $message ) { + echo '

    ' . esc_html( $message ) . '

    '; + } + } + } + + /** + * Settings page. + * + * Handles the display of the main sportspress settings page in admin. + * + * @access public + * @return void + */ + public static function output() { + global $current_section, $current_tab; + + do_action( 'sportspress_settings_start' ); + + wp_enqueue_script( 'sportspress_settings', SP()->plugin_url() . '/assets/js/admin/settings.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'chosen' ), SP()->version, true ); + + wp_localize_script( + 'sportspress_settings', + 'localized_strings', + array( + 'none' => __( 'None', 'sportspress' ), + ) + ); + + // Include settings pages + self::get_settings_pages(); + + // Get current tab/section + $current_tab = empty( $_GET['tab'] ) ? 'modules' : sanitize_title( $_GET['tab'] ); + $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] ); + + // Save settings if data has been posted + if ( ! empty( $_POST ) ) { + self::save(); + } + + // Add any posted messages + if ( ! empty( $_GET['sp_error'] ) ) { + self::add_error( stripslashes( $_GET['sp_error'] ) ); + } + + if ( ! empty( $_GET['sp_message'] ) ) { + self::add_message( stripslashes( $_GET['sp_message'] ) ); + } + + self::show_messages(); + + // Get tabs for the settings page + $tabs = apply_filters( 'sportspress_settings_tabs_array', array() ); + + include 'views/html-admin-settings.php'; + } + + /** + * Get a setting from the settings API. + * + * @param mixed $option + * @return string + */ + public static function get_option( $option_name, $default = '' ) { + // Array value + if ( strstr( $option_name, '[' ) ) { + + parse_str( html_entity_decode( $option_name ), $option_array ); + + // Option name is first key + $option_name = current( array_keys( $option_array ) ); + + // Get value + $option_values = get_option( $option_name, '' ); + + $key = key( $option_array[ $option_name ] ); + + if ( isset( $option_values[ $key ] ) ) { + $option_value = $option_values[ $key ]; + } else { + $option_value = null; + } + + // Single value } else { - $description = $tip = ''; + $option_value = get_option( $option_name, null ); } - if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) { - $description = '

    ' . wp_kses_post( $description ) . '

    '; - } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) { - $description = wp_kses_post( $description ); - } elseif ( $description && in_array( $value['type'], array( 'select' ) ) ) { - $description = '

    ' . wp_kses_post( $description ) . '

    '; - } elseif ( $description ) { - $description = '' . wp_kses_post( $description ) . ''; + if ( is_array( $option_value ) ) { + $option_value = array_map( 'stripslashes', $option_value ); + } elseif ( ! is_null( $option_value ) ) { + $option_value = stripslashes( $option_value ); } - if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) { + return $option_value === null ? $default : $option_value; + } - $tip = '

    ' . $tip . '

    '; + /** + * Output admin fields. + * + * Loops though the sportspress options array and outputs each field. + * + * @access public + * @param array $options Opens array to output + */ + public static function output_fields( $options ) { + foreach ( $options as $value ) { + if ( ! isset( $value['type'] ) ) { + continue; + } + if ( ! isset( $value['id'] ) ) { + $value['id'] = ''; + } + if ( ! isset( $value['title'] ) ) { + $value['title'] = isset( $value['name'] ) ? $value['name'] : ''; + } + if ( ! isset( $value['class'] ) ) { + $value['class'] = ''; + } + if ( ! isset( $value['css'] ) ) { + $value['css'] = ''; + } + if ( ! isset( $value['default'] ) ) { + $value['default'] = ''; + } + if ( ! isset( $value['desc'] ) ) { + $value['desc'] = ''; + } + if ( ! isset( $value['desc_tip'] ) ) { + $value['desc_tip'] = false; + } + if ( ! isset( $value['placeholder'] ) ) { + $value['placeholder'] = ''; + } - } elseif ( $tip ) { + // Custom attribute handling + $custom_attributes = array(); - $tip = ''; + if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) { + foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) { + $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; + } + } - } + // Description handling + if ( $value['desc_tip'] === true ) { + $description = ''; + $tip = $value['desc']; + } elseif ( ! empty( $value['desc_tip'] ) ) { + $description = $value['desc']; + $tip = $value['desc_tip']; + } elseif ( ! empty( $value['desc'] ) ) { + $description = $value['desc']; + $tip = ''; + } else { + $description = $tip = ''; + } - // Switch based on type - switch( $value['type'] ) { + if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) { + $description = '

    ' . wp_kses_post( $description ) . '

    '; + } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) { + $description = wp_kses_post( $description ); + } elseif ( $description && in_array( $value['type'], array( 'select' ) ) ) { + $description = '

    ' . wp_kses_post( $description ) . '

    '; + } elseif ( $description ) { + $description = '' . wp_kses_post( $description ) . ''; + } - // Section Titles - case 'title': - echo '
    '; - echo ''; - if ( ! empty( $value['title'] ) ) { - echo '

    ' . esc_html( $value['title'] ) . '

    '; - } - if ( ! empty( $value['desc'] ) ) { - echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); - } - echo ''. "\n\n"; - if ( ! empty( $value['id'] ) ) { - do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) ); - } - break; + if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) { - // Section Ends - case 'sectionend': - if ( ! empty( $value['id'] ) ) { - do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) . '_end' ); - } - echo '
    '; - if ( ! empty( $value['id'] ) ) { - do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) . '_after' ); - } - echo '
    '; - break; + $tip = '

    ' . $tip . '

    '; - // Standard text inputs and subtypes like 'number' - case 'text': - case 'email': - case 'number': - case 'color' : - case 'password' : + } elseif ( $tip ) { - $type = $value['type']; - $class = ''; - $option_value = self::get_option( $value['id'], $value['default'] ); + $tip = ''; - if ( $value['type'] == 'color' ) { - $type = 'text'; - $value['class'] .= 'colorpick'; - $description .= ''; - } + } - ?> + // Switch based on type + switch ( $value['type'] ) { + + // Section Titles + case 'title': + echo '
    '; + echo ''; + if ( ! empty( $value['title'] ) ) { + echo '

    ' . esc_html( $value['title'] ) . '

    '; + } + if ( ! empty( $value['desc'] ) ) { + echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); + } + echo '' . "\n\n"; + if ( ! empty( $value['id'] ) ) { + do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) ); + } + break; + + // Section Ends + case 'sectionend': + if ( ! empty( $value['id'] ) ) { + do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) . '_end' ); + } + echo '
    '; + if ( ! empty( $value['id'] ) ) { + do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) . '_after' ); + } + echo '
    '; + break; + + // Standard text inputs and subtypes like 'number' + case 'text': + case 'email': + case 'number': + case 'color': + case 'password': + $type = $value['type']; + $class = ''; + $option_value = self::get_option( $value['id'], $value['default'] ); + + if ( $value['type'] == 'color' ) { + $type = 'text'; + $value['class'] .= 'colorpick'; + $description .= ''; + } + + ?> - - - /> - - "> + + /> + + + + ?> + - - + + - - - " + id="" + style="" + class="" + + > + + + + ?> + - - + + > + $val ) { + ?> + - - - - + > + + + + + + ?> + - - + + > + $options ) { + ?> + + $val ) { + ?> + - - - - - - + > + + + + + + + + ?> + - - + + > + $options ) { + ?> + + $val ) { + ?> + - - - + ?> + > + + +

    - - + + + ?> + - -
    - -
      - $val ) { - ?> -
    • - -
    • - -
    -
    - - "> +
    + +
      + $val ) { + ?> +
    • + +
    • + +
    +
    + + + - - + if ( ! isset( $value['checkboxgroup'] ) || 'start' == $value['checkboxgroup'] ) { + ?> + +
    - -
    - +
    + - - + + + ?> - + if ( ! isset( $value['checkboxgroup'] ) || 'end' == $value['checkboxgroup'] ) { + ?>
    - +
    - $value ) { + update_option( $name, $value ); + } + + return true; } } - /** - * Save admin fields. - * - * Loops though the sportspress options array and outputs each field. - * - * @access public - * @param array $options Opens array to output - * @return bool - */ - public static function save_fields( $options ) { - if ( empty( $_POST ) ) - return false; - - // Options to update will be stored here - $update_options = array(); - - // Loop options and get values to save - foreach ( $options as $value ) { - - if ( ! isset( $value['id'] ) ) - continue; - - $type = isset( $value['type'] ) ? esc_attr( $value['type'] ) : ''; - - // Get the option name - $option_value = null; - - switch ( $type ) { - - // Standard types - case 'checkbox' : - - if ( isset( $_POST[ $value['id'] ] ) ) { - $option_value = 'yes'; - } else { - $option_value = 'no'; - } - - break; - - case 'textarea' : - - if ( isset( $_POST[$value['id']] ) ) { - $option_value = wp_kses_post( trim( stripslashes( $_POST[ $value['id'] ] ) ) ); - } else { - $option_value = ''; - } - - break; - - case 'text' : - case 'email': - case 'number': - case 'select' : - case 'groupselect' : - case 'sport' : - case 'color' : - case 'password' : - case 'radio' : - - if ( isset( $_POST[$value['id']] ) ) { - $option_value = sanitize_text_field( stripslashes( $_POST[ $value['id'] ] ) ); - } else { - $option_value = ''; - } - - break; - - // Special types - case "multiselect" : - case "multi_select_countries" : - - // Get countries array - if ( isset( $_POST[ $value['id'] ] ) ) - $selected_countries = array_map( 'sanitize_text_field', array_map( 'stripslashes', (array) $_POST[ $value['id'] ] ) ); - else - $selected_countries = array(); - - $option_value = $selected_countries; - - break; - - // Custom handling - default : - - do_action( 'sportspress_update_option_' . $type, $value ); - - break; - - } - - if ( ! is_null( $option_value ) ) { - // Check if option is an array - if ( strstr( $value['id'], '[' ) ) { - - parse_str( $value['id'], $option_array ); - - // Option name is first key - $option_name = current( array_keys( $option_array ) ); - - // Get old option value - if ( ! isset( $update_options[ $option_name ] ) ) - $update_options[ $option_name ] = get_option( $option_name, array() ); - - if ( ! is_array( $update_options[ $option_name ] ) ) - $update_options[ $option_name ] = array(); - - // Set keys and value - $key = key( $option_array[ $option_name ] ); - - $update_options[ $option_name ][ $key ] = $option_value; - - // Single value - } else { - $update_options[ $value['id'] ] = $option_value; - } - } - - // Custom handling - do_action( 'sportspress_update_option', $value ); - } - - // Now save the options - foreach( $update_options as $name => $value ) - update_option( $name, $value ); - - return true; - } -} - endif; diff --git a/includes/admin/class-sp-admin-setup-wizard.php b/includes/admin/class-sp-admin-setup-wizard.php index b7d5569e..2a486c1b 100644 --- a/includes/admin/class-sp-admin-setup-wizard.php +++ b/includes/admin/class-sp-admin-setup-wizard.php @@ -10,9 +10,9 @@ * @category Admin * @package SportsPress/Admin * @version 2.7.9 -*/ + */ if ( ! defined( 'ABSPATH' ) ) { - exit; + exit; } /** @@ -20,774 +20,872 @@ if ( ! defined( 'ABSPATH' ) ) { */ class SP_Admin_Setup_Wizard { - /** @var string Current Step */ - private $step = ''; - - /** @var array Steps for the setup wizard */ - private $steps = array(); - - /** @var array Tweets user can optionally send after install */ - private $tweets = array( - "Someone give me a high five, I just set up a new sports data website with #SportsPress and #WordPress!" - ); - - /** - * Hook in tabs. - */ - public function __construct() { - if ( apply_filters( 'sportspress_enable_setup_wizard', true ) && current_user_can( 'manage_sportspress' ) ) { - add_action( 'admin_menu', array( $this, 'admin_menus' ) ); - add_action( 'admin_init', array( $this, 'setup_wizard' ) ); - } - } - - /** - * Add admin menus/screens. - */ - public function admin_menus() { - add_dashboard_page( '', '', 'manage_options', 'sp-setup', '' ); - } - - /** - * Show the setup wizard. - */ - public function setup_wizard() { - if ( empty( $_GET['page'] ) || 'sp-setup' !== $_GET['page'] ) { - return; - } - $this->steps = array( - 'introduction' => array( - 'name' => __( 'Introduction', 'sportspress' ), - 'view' => array( $this, 'sp_setup_introduction' ), - 'handler' => '' - ), - 'basics' => array( - 'name' => __( 'Basic Setup', 'sportspress' ), - 'view' => array( $this, 'sp_setup_basics' ), - 'handler' => array( $this, 'sp_setup_basics_save' ) - ), - 'teams' => array( - 'name' => __( 'Teams', 'sportspress' ), - 'view' => array( $this, 'sp_setup_teams' ), - 'handler' => array( $this, 'sp_setup_teams_save' ) - ), - 'players_staff' => array( - 'name' => __( 'Players', 'sportspress' ) . ' & ' . __( 'Staff', 'sportspress' ), - 'view' => array( $this, 'sp_setup_players_staff' ), - 'handler' => array( $this, 'sp_setup_players_staff_save' ), - ), - 'venue' => array( - 'name' => __( 'Venue', 'sportspress' ), - 'view' => array( $this, 'sp_setup_venue' ), - 'handler' => array( $this, 'sp_setup_venue_save' ), - ), - 'pages' => array( - 'name' => __( 'Pages', 'sportspress' ), - 'view' => array( $this, 'sp_setup_pages' ), - 'handler' => array( $this, 'sp_setup_pages_save' ) - ), - 'next_steps' => array( - 'name' => __( 'Ready!', 'sportspress' ), - 'view' => array( $this, 'sp_setup_ready' ), - 'handler' => '' - ) - ); - $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; - - wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' ); - wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION ); - wp_enqueue_style( 'sportspress-setup', SP()->plugin_url() . '/assets/css/setup.css', array( 'dashicons', 'install' ), SP_VERSION ); - - wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true ); - wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true ); - wp_register_script( 'sportspress-setup', SP()->plugin_url() . '/assets/js/admin/sportspress-setup.js', array( 'jquery', 'chosen', 'jquery-tiptip' ), SP_VERSION, true ); - - do_action( 'sp_setup_geocoder_scripts' ); - - $strings = apply_filters( 'sportspress_localized_strings', array( - 'none' => __( 'None', 'sportspress' ), - 'remove_text' => __( '— Remove —', 'sportspress' ), - ) ); - - // Localize scripts - wp_localize_script( 'sportspress-setup', 'localized_strings', $strings ); - - if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { - call_user_func( $this->steps[ $this->step ]['handler'] ); - } - - ob_start(); - $this->setup_wizard_header(); - $this->setup_wizard_steps(); - $this->setup_wizard_content(); - $this->setup_wizard_footer(); - exit; - } - - public function get_next_step_link() { - $keys = array_keys( $this->steps ); - return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] ); - } - - /** - * Setup Wizard Header. - */ - public function setup_wizard_header() { - ?> - - > - - - - <?php _e( 'SportsPress', 'sportspress' ); ?> › <?php echo esc_html( $this->steps[ $this->step ]['name'] ); ?> - - - - -

    ' ); ?>

    - - step ) : ?> -

    - - - - - steps; - array_shift( $ouput_steps ); - ?> -
      - $step ) : ?> -
    1. - -
    - '; - call_user_func( $this->steps[ $this->step ]['view'] ); - echo ''; - } - - /** - * Introduction Step. - */ - public function sp_setup_introduction() { - ?> -

    -

    It’s completely optional and shouldn’t take longer than five minutes.', 'sportspress' ); ?>

    -

    -

    - - -

    - -

    -
    -

    - - - - - - - - - - - - - - - - - -
    - -
    - - -
    - -
    - -
    - -

    - - - -

    -
    - get_next_step_link() ) ); - exit; - } - - /** - * Team Setup. - */ - public function sp_setup_teams() { - $class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' ); - ?> -

    -
    -

    - - - - - - - - - -
    - -
    - -

    -
    - -

    - - - -

    -
    - 0, 'fields' => 'ids' ) ); - }; - wp_insert_post( $post ); - - // Add home team - $post['post_title'] = sanitize_text_field( $_POST['home_team'] ); - wp_insert_post( $post ); - - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); - exit; - } - - /** - * Players & Staff Setup. - */ - public function sp_setup_players_staff() { - $positions = (array) get_terms( 'sp_position', array( 'hide_empty' => 0, 'orderby' => 'slug', 'fields' => 'names' ) ) - ?> -

    -
    -

    - - - - - - - - - -
    -
      - -
    • value="">
    • - -
    -

    -
    -
      -
    • -
    -
    - -

    - - - -

    -
    - 1, 'post_type' => 'sp_team', 'fields' => 'ids' ) ); - $team = reset( $teams ); - - // Add players - $post['post_type'] = 'sp_player'; - $post['post_status'] = 'publish'; - $post['tax_input'] = array(); - $taxonomies = array( 'sp_league', 'sp_season' ); - foreach ( $taxonomies as $taxonomy ) { - $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); - }; - if ( is_array( $_POST['players'] ) ) { - foreach ( $_POST['players'] as $i => $player ) { - if ( empty( $player['name'] ) ) continue; - - $post['post_title'] = $player['name']; - $id = wp_insert_post( $post ); - - // Add squad number - $number = sanitize_text_field( sp_array_value( $player, 'number' ) ); - update_post_meta( $id, 'sp_number', $number ); - - // Add position - wp_set_object_terms( $id, sp_array_value( $player, 'position', __( 'Position', 'sportspress' ) ), 'sp_position', false ); - - // Add team - if ( $team ) { - update_post_meta( $id, 'sp_team', $team ); - update_post_meta( $id, 'sp_current_team', $team ); - } - } - } - - // Add staff - if ( ! empty( $_POST['staff'] ) ) { - - $post['post_type'] = 'sp_staff'; - $post['post_title'] = sanitize_text_field( $_POST['staff'] ); - $id = wp_insert_post( $post ); - - // Add role - wp_set_object_terms( $id, sp_array_value( $_POST, 'role', 'Coach' ), 'sp_role', false ); - - // Add team - if ( $team ) { - update_post_meta( $id, 'sp_team', $team ); - update_post_meta( $id, 'sp_current_team', $team ); - } - } - - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); - exit; - } - - /** - * Venue Step. - */ - public function sp_setup_venue() { - do_action( 'sp_setup_venue_geocoder_scripts' ); - ?> -

    -
    -

    - - - - - - - - - -
    - -
    - -
    -

    - - -
    - -

    - - - -

    -
    - 1, 'post_type' => 'sp_team', 'fields' => 'ids' ) ); - $team = reset( $teams ); - - // Insert venue - $venue = sanitize_text_field( $_POST['venue'] ); - if ( ! is_string( $venue ) || empty( $venue ) ) { - $venue = sp_array_value( $_POST, 'address', __( 'Venue', 'sportspress' ) ); - } - $inserted = wp_insert_term( $venue, 'sp_venue' ); - - // Add address and coordinates to venue - if ( ! is_wp_error( $inserted ) ) { - $t_id = sp_array_value( $inserted, 'term_id', 1 ); - - if ( $team ) { - wp_set_object_terms( $team, $t_id, 'sp_venue', true ); - } - - $meta = array( - 'sp_address' => sanitize_text_field( sp_array_value( $_POST, 'address' ) ), - 'sp_latitude' => sanitize_text_field( sp_array_value( $_POST, 'latitude' ) ), - 'sp_longitude' => sanitize_text_field( sp_array_value( $_POST, 'longitude' ) ), - ); - update_option( "taxonomy_$t_id", $meta ); - } - - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); - exit; - } - - /** - * Pages Step. - */ - public function sp_setup_pages() { - $pages = apply_filters( 'sportspress_setup_pages', array( - 'sp_calendar' => __( 'Organize and publish calendars using different layouts.', 'sportspress' ), - 'sp_table' => __( 'Create automated league tables to keep track of team standings.', 'sportspress' ), - 'sp_list' => __( 'Create team rosters, player galleries, and ranking charts.', 'sportspress' ), - ) ); - ?> -

    -
    -

    ', '' ); ?>

    - - $description ) { ?> - - - - - - -
    labels->singular_name ); ?>
    - -

    ', '', '', '' ); ?>

    - -

    - - - -

    -
    - __( 'Organize and publish calendars using different layouts.', 'sportspress' ), - 'sp_table' => __( 'Create automated league tables to keep track of team standings.', 'sportspress' ), - 'sp_list' => __( 'Create team rosters, player galleries, and ranking charts.', 'sportspress' ), - ) ); - - // Initialize post - $post = array( 'post_status' => 'publish' ); - $sample_content = _x( 'This is an example %1$s. As a new SportsPress user, you should go to your dashboard to delete this %1$s and create new %2$s for your content. Have fun!', 'example', 'sportspress' ); - - // Insert posts - foreach ( $pages as $post_type => $description ) { - $obj = get_post_type_object( $post_type ); - if ( ! is_object( $obj ) ) continue; - - // Skip if post exists - $posts = get_posts( array( 'posts_per_page' => 1, 'post_type' => $post_type ) ); - if ( $posts ) continue; - - // Add post args - $post['post_title'] = $obj->labels->singular_name; - $post['post_type'] = $post_type; - $post['post_content'] = sprintf( $sample_content, $obj->labels->singular_name, $obj->labels->name, add_query_arg( 'post_type', $post_type, admin_url( 'edit.php' ) ) ); - - // Insert post - $id = wp_insert_post( $post ); - - // Flag as sample - update_post_meta( $id, '_sp_sample', 1 ); - } - - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); - exit; - } - - /** - * Actions on the final step. - */ - private function sp_setup_ready_actions() { - delete_option( '_sp_needs_welcome' ); - update_option( 'sportspress_installed', 1 ); - update_option( 'sportspress_completed_setup', 1 ); - delete_transient( '_sp_activation_redirect' ); - - // Check if first event already exists - $events = get_posts( - array( - 'post_type' => 'sp_event', - 'posts_per_page' => 1, - 'post_status' => 'draft', - 'meta_query' => array( - array( - 'key' => '_sp_first', - 'value' => 1 - ) - ) - ) - ); - - if ( $events ) { - $event = reset( $events ); - return $event->ID; - } - - // Get teams - $team_post_type = 'sp_team'; - if ( 'player' === get_option( 'sportspress_mode', 'team' ) ) { - $team_post_type = 'sp_player'; - } - $teams = get_posts( array( 'posts_per_page' => 2, 'post_type' => $team_post_type ) ); - - // Get players - $players = (array) get_posts( array( 'posts_per_page' => 3, 'post_type' => 'sp_player', 'fields' => 'ids' ) ); - - // Get staff - $staff = (array) get_posts( array( 'posts_per_page' => 1, 'post_type' => 'sp_staff', 'fields' => 'ids' ) ); - - // Initialize post - $post['post_type'] = 'sp_event'; - $post['post_status'] = 'draft'; - $post['tax_input'] = array(); - - // Add taxonomies - $taxonomies = array( 'sp_league', 'sp_season', 'sp_venue' ); - foreach ( $taxonomies as $taxonomy ) { - $post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids', 'number' => 1 ) ); - }; - - // Add post title - if ( is_array( $teams ) && sizeof( $teams ) ) { - $team_names = array(); - foreach ( $teams as $team ) { - if ( ! $team ) continue; - $team_names[] = $team->post_title; - } - $post['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names ); - } else { - $post['post_title'] = __( 'Event', 'sportspress' ); - } - - // Insert event - $id = wp_insert_post( $post ); - - // Add teams - if ( is_array( $teams ) && sizeof( $teams ) ) { - foreach ( $teams as $team ) { - if ( ! $team ) continue; - add_post_meta( $id, 'sp_team', $team->ID ); - } - } - - // Add players - add_post_meta( $id, 'sp_player', 0 ); - foreach ( $players as $player ) { - if ( ! $player ) continue; - add_post_meta( $id, 'sp_player', $player ); - } - add_post_meta( $id, 'sp_player', 0 ); - - update_post_meta( $id, '_sp_first', 1 ); - - return $id; - } - - /** - * Final step. - */ - public function sp_setup_ready() { - $id = $this->sp_setup_ready_actions(); - shuffle( $this->tweets ); - - $steps = apply_filters( 'sportspress_setup_wizard_next_steps', array( - 'first' => array( - 'label' => __( 'Next Steps', 'sportspress' ), - 'content' => '' . __( 'Schedule your first event!', 'sportspress' ) . '', - ), - 'last' => array( - 'label' => __( 'Upgrade to Pro', 'sportspress' ), - 'content' => __( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.', 'sportspress' ) . ' ' . __( 'Learn more', 'sportspress' ) . '', - ), - ) ); - ?> - - - -

    - -
    - -
    - $step ) { ?> -
    -

    -
      -
    • -
    -
    - -
    - steps = array( + 'introduction' => array( + 'name' => __( 'Introduction', 'sportspress' ), + 'view' => array( $this, 'sp_setup_introduction' ), + 'handler' => '', + ), + 'basics' => array( + 'name' => __( 'Basic Setup', 'sportspress' ), + 'view' => array( $this, 'sp_setup_basics' ), + 'handler' => array( $this, 'sp_setup_basics_save' ), + ), + 'teams' => array( + 'name' => __( 'Teams', 'sportspress' ), + 'view' => array( $this, 'sp_setup_teams' ), + 'handler' => array( $this, 'sp_setup_teams_save' ), + ), + 'players_staff' => array( + 'name' => __( 'Players', 'sportspress' ) . ' & ' . __( 'Staff', 'sportspress' ), + 'view' => array( $this, 'sp_setup_players_staff' ), + 'handler' => array( $this, 'sp_setup_players_staff_save' ), + ), + 'venue' => array( + 'name' => __( 'Venue', 'sportspress' ), + 'view' => array( $this, 'sp_setup_venue' ), + 'handler' => array( $this, 'sp_setup_venue_save' ), + ), + 'pages' => array( + 'name' => __( 'Pages', 'sportspress' ), + 'view' => array( $this, 'sp_setup_pages' ), + 'handler' => array( $this, 'sp_setup_pages_save' ), + ), + 'next_steps' => array( + 'name' => __( 'Ready!', 'sportspress' ), + 'view' => array( $this, 'sp_setup_ready' ), + 'handler' => '', + ), + ); + $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' ); + wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION ); + wp_enqueue_style( 'sportspress-setup', SP()->plugin_url() . '/assets/css/setup.css', array( 'dashicons', 'install' ), SP_VERSION ); + + wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true ); + wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true ); + wp_register_script( 'sportspress-setup', SP()->plugin_url() . '/assets/js/admin/sportspress-setup.js', array( 'jquery', 'chosen', 'jquery-tiptip' ), SP_VERSION, true ); + + do_action( 'sp_setup_geocoder_scripts' ); + + $strings = apply_filters( + 'sportspress_localized_strings', + array( + 'none' => __( 'None', 'sportspress' ), + 'remove_text' => __( '— Remove —', 'sportspress' ), + ) + ); + + // Localize scripts + wp_localize_script( 'sportspress-setup', 'localized_strings', $strings ); + + if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { + call_user_func( $this->steps[ $this->step ]['handler'] ); + } + + ob_start(); + $this->setup_wizard_header(); + $this->setup_wizard_steps(); + $this->setup_wizard_content(); + $this->setup_wizard_footer(); + exit; + } + + public function get_next_step_link() { + $keys = array_keys( $this->steps ); + return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] ); + } + + /** + * Setup Wizard Header. + */ + public function setup_wizard_header() { + ?> + + > + + + + <?php _e( 'SportsPress', 'sportspress' ); ?> › <?php echo esc_html( $this->steps[ $this->step ]['name'] ); ?> + + + + +

    ' ); ?>

    + + step ) : ?> +

    + + + + + steps; + array_shift( $ouput_steps ); + ?> +
      + $step ) : ?> +
    1. + +
    + '; + call_user_func( $this->steps[ $this->step ]['view'] ); + echo ''; + } + + /** + * Introduction Step. + */ + public function sp_setup_introduction() { + ?> +

    +

    It’s completely optional and shouldn’t take longer than five minutes.', 'sportspress' ); ?>

    +

    +

    + + +

    + +

    +
    +

    + + + + + + + + + + + + + + + + + +
    + +
    + + +
    + +
    + +
    + +

    + + + +

    +
    + get_next_step_link() ) ); + exit; + } + + /** + * Team Setup. + */ + public function sp_setup_teams() { + $class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' ); + ?> +

    +
    +

    + + + + + + + + + +
    + +
    + +

    +
    + +

    + + + +

    +
    + 0, + 'fields' => 'ids', + ) + ); + } + wp_insert_post( $post ); + + // Add home team + $post['post_title'] = sanitize_text_field( $_POST['home_team'] ); + wp_insert_post( $post ); + + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + + /** + * Players & Staff Setup. + */ + public function sp_setup_players_staff() { + $positions = (array) get_terms( + 'sp_position', + array( + 'hide_empty' => 0, + 'orderby' => 'slug', + 'fields' => 'names', + ) + ) + ?> +

    +
    +

    + + + + + + + + + +
    +
      + +
    • + value="">
    • + +
    +

    +
    +
      +
    • +
    +
    + +

    + + + +

    +
    + 1, + 'post_type' => 'sp_team', + 'fields' => 'ids', + ) + ); + $team = reset( $teams ); + + // Add players + $post['post_type'] = 'sp_player'; + $post['post_status'] = 'publish'; + $post['tax_input'] = array(); + $taxonomies = array( 'sp_league', 'sp_season' ); + foreach ( $taxonomies as $taxonomy ) { + $post['tax_input'][ $taxonomy ] = get_terms( + $taxonomy, + array( + 'hide_empty' => 0, + 'fields' => 'ids', + ) + ); + } + if ( is_array( $_POST['players'] ) ) { + foreach ( $_POST['players'] as $i => $player ) { + if ( empty( $player['name'] ) ) { + continue; + } + + $post['post_title'] = $player['name']; + $id = wp_insert_post( $post ); + + // Add squad number + $number = sanitize_text_field( sp_array_value( $player, 'number' ) ); + update_post_meta( $id, 'sp_number', $number ); + + // Add position + wp_set_object_terms( $id, sp_array_value( $player, 'position', __( 'Position', 'sportspress' ) ), 'sp_position', false ); + + // Add team + if ( $team ) { + update_post_meta( $id, 'sp_team', $team ); + update_post_meta( $id, 'sp_current_team', $team ); + } + } + } + + // Add staff + if ( ! empty( $_POST['staff'] ) ) { + + $post['post_type'] = 'sp_staff'; + $post['post_title'] = sanitize_text_field( $_POST['staff'] ); + $id = wp_insert_post( $post ); + + // Add role + wp_set_object_terms( $id, sp_array_value( $_POST, 'role', 'Coach' ), 'sp_role', false ); + + // Add team + if ( $team ) { + update_post_meta( $id, 'sp_team', $team ); + update_post_meta( $id, 'sp_current_team', $team ); + } + } + + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + + /** + * Venue Step. + */ + public function sp_setup_venue() { + do_action( 'sp_setup_venue_geocoder_scripts' ); + ?> +

    +
    +

    + + + + + + + + + +
    + +
    + +
    +

    + + +
    + +

    + + + +

    +
    + 1, + 'post_type' => 'sp_team', + 'fields' => 'ids', + ) + ); + $team = reset( $teams ); + + // Insert venue + $venue = sanitize_text_field( $_POST['venue'] ); + if ( ! is_string( $venue ) || empty( $venue ) ) { + $venue = sp_array_value( $_POST, 'address', __( 'Venue', 'sportspress' ) ); + } + $inserted = wp_insert_term( $venue, 'sp_venue' ); + + // Add address and coordinates to venue + if ( ! is_wp_error( $inserted ) ) { + $t_id = sp_array_value( $inserted, 'term_id', 1 ); + + if ( $team ) { + wp_set_object_terms( $team, $t_id, 'sp_venue', true ); + } + + $meta = array( + 'sp_address' => sanitize_text_field( sp_array_value( $_POST, 'address' ) ), + 'sp_latitude' => sanitize_text_field( sp_array_value( $_POST, 'latitude' ) ), + 'sp_longitude' => sanitize_text_field( sp_array_value( $_POST, 'longitude' ) ), + ); + update_option( "taxonomy_$t_id", $meta ); + } + + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + + /** + * Pages Step. + */ + public function sp_setup_pages() { + $pages = apply_filters( + 'sportspress_setup_pages', + array( + 'sp_calendar' => __( 'Organize and publish calendars using different layouts.', 'sportspress' ), + 'sp_table' => __( 'Create automated league tables to keep track of team standings.', 'sportspress' ), + 'sp_list' => __( 'Create team rosters, player galleries, and ranking charts.', 'sportspress' ), + ) + ); + ?> +

    +
    +

    ', '' ); ?>

    + + $description ) { ?> + + + + + + +
    labels->singular_name ); ?>
    + +

    ', '', '', '' ); ?>

    + +

    + + + +

    +
    + __( 'Organize and publish calendars using different layouts.', 'sportspress' ), + 'sp_table' => __( 'Create automated league tables to keep track of team standings.', 'sportspress' ), + 'sp_list' => __( 'Create team rosters, player galleries, and ranking charts.', 'sportspress' ), + ) + ); + + // Initialize post + $post = array( 'post_status' => 'publish' ); + $sample_content = _x( 'This is an example %1$s. As a new SportsPress user, you should go to your dashboard to delete this %1$s and create new %2$s for your content. Have fun!', 'example', 'sportspress' ); + + // Insert posts + foreach ( $pages as $post_type => $description ) { + $obj = get_post_type_object( $post_type ); + if ( ! is_object( $obj ) ) { + continue; + } + + // Skip if post exists + $posts = get_posts( + array( + 'posts_per_page' => 1, + 'post_type' => $post_type, + ) + ); + if ( $posts ) { + continue; + } + + // Add post args + $post['post_title'] = $obj->labels->singular_name; + $post['post_type'] = $post_type; + $post['post_content'] = sprintf( $sample_content, $obj->labels->singular_name, $obj->labels->name, add_query_arg( 'post_type', $post_type, admin_url( 'edit.php' ) ) ); + + // Insert post + $id = wp_insert_post( $post ); + + // Flag as sample + update_post_meta( $id, '_sp_sample', 1 ); + } + + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + + /** + * Actions on the final step. + */ + private function sp_setup_ready_actions() { + delete_option( '_sp_needs_welcome' ); + update_option( 'sportspress_installed', 1 ); + update_option( 'sportspress_completed_setup', 1 ); + delete_transient( '_sp_activation_redirect' ); + + // Check if first event already exists + $events = get_posts( + array( + 'post_type' => 'sp_event', + 'posts_per_page' => 1, + 'post_status' => 'draft', + 'meta_query' => array( + array( + 'key' => '_sp_first', + 'value' => 1, + ), + ), + ) + ); + + if ( $events ) { + $event = reset( $events ); + return $event->ID; + } + + // Get teams + $team_post_type = 'sp_team'; + if ( 'player' === get_option( 'sportspress_mode', 'team' ) ) { + $team_post_type = 'sp_player'; + } + $teams = get_posts( + array( + 'posts_per_page' => 2, + 'post_type' => $team_post_type, + ) + ); + + // Get players + $players = (array) get_posts( + array( + 'posts_per_page' => 3, + 'post_type' => 'sp_player', + 'fields' => 'ids', + ) + ); + + // Get staff + $staff = (array) get_posts( + array( + 'posts_per_page' => 1, + 'post_type' => 'sp_staff', + 'fields' => 'ids', + ) + ); + + // Initialize post + $post['post_type'] = 'sp_event'; + $post['post_status'] = 'draft'; + $post['tax_input'] = array(); + + // Add taxonomies + $taxonomies = array( 'sp_league', 'sp_season', 'sp_venue' ); + foreach ( $taxonomies as $taxonomy ) { + $post['tax_input'][ $taxonomy ] = get_terms( + $taxonomy, + array( + 'hide_empty' => 0, + 'fields' => 'ids', + 'number' => 1, + ) + ); + } + + // Add post title + if ( is_array( $teams ) && sizeof( $teams ) ) { + $team_names = array(); + foreach ( $teams as $team ) { + if ( ! $team ) { + continue; + } + $team_names[] = $team->post_title; + } + $post['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names ); + } else { + $post['post_title'] = __( 'Event', 'sportspress' ); + } + + // Insert event + $id = wp_insert_post( $post ); + + // Add teams + if ( is_array( $teams ) && sizeof( $teams ) ) { + foreach ( $teams as $team ) { + if ( ! $team ) { + continue; + } + add_post_meta( $id, 'sp_team', $team->ID ); + } + } + + // Add players + add_post_meta( $id, 'sp_player', 0 ); + foreach ( $players as $player ) { + if ( ! $player ) { + continue; + } + add_post_meta( $id, 'sp_player', $player ); + } + add_post_meta( $id, 'sp_player', 0 ); + + update_post_meta( $id, '_sp_first', 1 ); + + return $id; + } + + /** + * Final step. + */ + public function sp_setup_ready() { + $id = $this->sp_setup_ready_actions(); + shuffle( $this->tweets ); + + $steps = apply_filters( + 'sportspress_setup_wizard_next_steps', + array( + 'first' => array( + 'label' => __( 'Next Steps', 'sportspress' ), + 'content' => '' . __( 'Schedule your first event!', 'sportspress' ) . '', + ), + 'last' => array( + 'label' => __( 'Upgrade to Pro', 'sportspress' ), + 'content' => __( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.', 'sportspress' ) . ' ' . __( 'Learn more', 'sportspress' ) . '', + ), + ) + ); + ?> + + + +

    + +
    + +
    + $step ) { ?> +
    +

    +
      +
    • +
    +
    + +
    + array(), + 'team-sports' => array(), 'racket-sports' => array(), - 'water-sports' => array(), + 'water-sports' => array(), 'target-sports' => array(), - 'esports' => array(), - 'other' => array(), + 'esports' => array(), + 'other' => array(), ); foreach ( self::$options as $slug => $options ) { - $dir = scandir( SP()->plugin_path() . '/presets/' . $slug ); + $dir = scandir( SP()->plugin_path() . '/presets/' . $slug ); $files = array(); if ( $dir ) { foreach ( $dir as $key => $value ) { @@ -40,13 +40,15 @@ class SP_Admin_Sports { } } } - foreach( $files as $file ) { + foreach ( $files as $file ) { $json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $slug . '/' . $file ); - $data = json_decode( $json_data, true ); - if ( ! is_array( $data ) ) continue; - $id = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file ); + $data = json_decode( $json_data, true ); + if ( ! is_array( $data ) ) { + continue; + } + $id = preg_replace( '/\\.[^.\\s]{3,4}$/', '', $file ); $presets[ $id ] = $data; - $name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id; + $name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id; // Conditionally append filename in parentheses for clarity if ( false === strpos( str_replace( ' ', '', strtolower( $data['name'] ) ), str_replace( '-', '', $id ) ) ) { @@ -69,15 +71,19 @@ class SP_Admin_Sports { public static function get_preset( $id ) { $json_data = @file_get_contents( SP()->plugin_path() . '/presets/' . $id . '.json', true ); - - if ( $json_data ) return json_decode( $json_data, true ); - + + if ( $json_data ) { + return json_decode( $json_data, true ); + } + $dir = scandir( SP()->plugin_path() . '/presets' ); if ( $dir ) { foreach ( $dir as $key => $value ) { if ( substr( $value, 0, 1 ) !== '.' && strpos( $value, '.' ) === false ) { $json_data = @file_get_contents( SP()->plugin_path() . '/presets/' . $value . '/' . $id . '.json', true ); - if ( $json_data ) return json_decode( $json_data, true ); + if ( $json_data ) { + return json_decode( $json_data, true ); + } } } } @@ -99,19 +105,21 @@ class SP_Admin_Sports { // Positions $positions = sp_array_value( $preset, 'positions', array() ); - $i = 0; + $i = 0; foreach ( $positions as $position ) { if ( is_string( $position ) ) { - $name = $position; + $name = $position; $sections = array( 0, 1 ); } else { - $name = sp_array_value( $position, 'name', __( 'Position', 'sportspress' ) ); + $name = sp_array_value( $position, 'name', __( 'Position', 'sportspress' ) ); $sections = sp_array_value( $position, 'sections', array( 0, 1 ) ); } $term = wp_insert_term( $name, 'sp_position' ); - if ( is_wp_error( $term ) ) continue; - $t_id = $term['term_id']; - $term_meta = get_option( "taxonomy_$t_id" ); + if ( is_wp_error( $term ) ) { + continue; + } + $t_id = $term['term_id']; + $term_meta = get_option( "taxonomy_$t_id" ); $term_meta['sp_sections'] = $sections; update_option( "taxonomy_$t_id", $term_meta ); update_term_meta( $t_id, 'sp_order', $i + 1 ); @@ -120,11 +128,13 @@ class SP_Admin_Sports { // Outcomes $post_type = 'sp_outcome'; - $outcomes = sp_array_value( $preset, 'outcomes', array() ); + $outcomes = sp_array_value( $preset, 'outcomes', array() ); self::delete_preset_posts( $post_type ); foreach ( $outcomes as $index => $outcome ) { $post = self::get_post_array( $outcome, $post_type ); - if ( empty( $post ) ) continue; + if ( empty( $post ) ) { + continue; + } $id = self::insert_preset_post( $post, $index ); update_post_meta( $id, 'sp_abbreviation', sp_array_value( $outcome, 'abbreviation', null ) ); update_post_meta( $id, 'sp_condition', sp_array_value( $outcome, 'condition', null ) ); @@ -132,14 +142,18 @@ class SP_Admin_Sports { // Results $post_type = 'sp_result'; - $results = sp_array_value( $preset, 'results', array() ); + $results = sp_array_value( $preset, 'results', array() ); self::delete_preset_posts( $post_type ); $primary_result = 0; foreach ( $results as $index => $result ) { $post = self::get_post_array( $result, $post_type ); - if ( empty( $post ) ) continue; + if ( empty( $post ) ) { + continue; + } $id = self::insert_preset_post( $post, $index ); - if ( is_array( $result ) && array_key_exists( 'primary', $result ) ) $primary_result = $post['post_name']; + if ( is_array( $result ) && array_key_exists( 'primary', $result ) ) { + $primary_result = $post['post_name']; + } update_post_meta( $id, 'sp_equation', sp_array_value( $result, 'equation', null ) ); } @@ -147,12 +161,14 @@ class SP_Admin_Sports { $i = 0; // Performance - $post_type = 'sp_performance'; + $post_type = 'sp_performance'; $performances = sp_array_value( $preset, 'performance', array() ); self::delete_preset_posts( $post_type ); foreach ( $performances as $index => $performance ) { $post = self::get_post_array( $performance, $post_type ); - if ( empty( $post ) ) continue; + if ( empty( $post ) ) { + continue; + } $id = self::insert_preset_post( $post, $index ); if ( isset( $performance['position'] ) ) { wp_set_object_terms( $id, $performance['position'], 'sp_position', false ); @@ -170,11 +186,13 @@ class SP_Admin_Sports { // Columns $post_type = 'sp_column'; - $columns = sp_array_value( $preset, 'columns', array() ); + $columns = sp_array_value( $preset, 'columns', array() ); self::delete_preset_posts( $post_type ); foreach ( $columns as $index => $column ) { $post = self::get_post_array( $column, $post_type ); - if ( empty( $post ) ) continue; + if ( empty( $post ) ) { + continue; + } $id = self::insert_preset_post( $post, $index ); update_post_meta( $id, 'sp_equation', sp_array_value( $column, 'equation', null ) ); update_post_meta( $id, 'sp_precision', sp_array_value( $column, 'precision', 0 ) ); @@ -184,40 +202,45 @@ class SP_Admin_Sports { // Metrics $post_type = 'sp_metric'; - $metrics = sp_array_value( $preset, 'metrics', array() ); + $metrics = sp_array_value( $preset, 'metrics', array() ); self::delete_preset_posts( $post_type ); foreach ( $metrics as $index => $metric ) { $post = self::get_post_array( $metric, $post_type ); - if ( empty( $post ) ) continue; + if ( empty( $post ) ) { + continue; + } $id = self::insert_preset_post( $post, $i + $index ); $i ++; } - + // Event Specs $post_type = 'sp_spec'; - $specs = sp_array_value( $preset, 'specs', array() ); + $specs = sp_array_value( $preset, 'specs', array() ); self::delete_preset_posts( $post_type ); foreach ( $specs as $index => $spec ) { $post = self::get_post_array( $spec, $post_type ); - if ( empty( $post ) ) continue; + if ( empty( $post ) ) { + continue; + } $id = self::insert_preset_post( $post, $i + $index ); $i ++; } // Statistics - $post_type = 'sp_statistic'; + $post_type = 'sp_statistic'; $statistics = sp_array_value( $preset, 'statistics', array() ); self::delete_preset_posts( $post_type ); foreach ( $statistics as $index => $statistic ) { $post = self::get_post_array( $statistic, $post_type ); - if ( empty( $post ) ) continue; + if ( empty( $post ) ) { + continue; + } $id = self::insert_preset_post( $post, $i + $index ); update_post_meta( $id, 'sp_equation', sp_array_value( $statistic, 'equation', null ) ); update_post_meta( $id, 'sp_precision', sp_array_value( $statistic, 'precision', 0 ) ); update_post_meta( $id, 'sp_type', sp_array_value( $statistic, 'type', 'total' ) ); } - // Options $options = sp_array_value( $preset, 'options', array() ); foreach ( $options as $option => $value ) { @@ -230,20 +253,20 @@ class SP_Admin_Sports { public static function delete_preset_posts( $post_type = null ) { $args = array( - 'post_type' => $post_type, + 'post_type' => $post_type, 'posts_per_page' => -1, - 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), - 'meta_query' => array( + 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), + 'meta_query' => array( array( - 'key' => '_sp_preset', - 'value' => 1 - ) - ) + 'key' => '_sp_preset', + 'value' => 1, + ), + ), ); // Delete posts $old_posts = get_posts( $args ); - foreach( $old_posts as $post ): + foreach ( $old_posts as $post ) : wp_delete_post( $post->ID, true ); endforeach; } @@ -252,15 +275,19 @@ class SP_Admin_Sports { $post_array = array(); if ( is_string( $post ) ) { $post_array['post_title'] = $post; - $post_array['post_name'] = sp_get_eos_safe_slug( $post_array['post_title'] ); + $post_array['post_name'] = sp_get_eos_safe_slug( $post_array['post_title'] ); } elseif ( is_array( $post ) ) { - if ( ! array_key_exists( 'name', $post ) ) $post_array = array(); + if ( ! array_key_exists( 'name', $post ) ) { + $post_array = array(); + } $post_array['post_title'] = $post['name']; - $post_array['post_name'] = sp_array_value( $post, 'id', sp_get_eos_safe_slug( $post_array['post_title'] ) ); + $post_array['post_name'] = sp_array_value( $post, 'id', sp_get_eos_safe_slug( $post_array['post_title'] ) ); } // Return empty array if post with same slug already exists - if ( get_page_by_path( $post_array['post_name'], OBJECT, $post_type ) ) return array(); + if ( get_page_by_path( $post_array['post_name'], OBJECT, $post_type ) ) { + return array(); + } // Set post type $post_array['post_type'] = $post_type; @@ -275,9 +302,9 @@ class SP_Admin_Sports { public static function insert_preset_post( $post, $index = 0 ) { // Increment menu order by 10 and publish post - $post['menu_order'] = $index * 10 + 10; + $post['menu_order'] = $index * 10 + 10; $post['post_status'] = 'publish'; - $id = wp_insert_post( $post ); + $id = wp_insert_post( $post ); // Flag as preset update_post_meta( $id, '_sp_preset', 1 ); @@ -287,21 +314,26 @@ class SP_Admin_Sports { /** * Sport category names + * * @return null */ public static function sport_category_names() { - return apply_filters( 'sportspress_sport_categories', array( - 'team-sports' => __( 'Team Sports', 'sportspress' ), - 'racket-sports' => __( 'Racket Sports', 'sportspress' ), - 'water-sports' => __( 'Water Sports', 'sportspress' ), - 'target-sports' => __( 'Target Sports', 'sportspress' ), - 'esports' => __( 'Esports', 'sportspress' ), - 'other' => __( 'Other', 'sportspress' ), - ) ); + return apply_filters( + 'sportspress_sport_categories', + array( + 'team-sports' => __( 'Team Sports', 'sportspress' ), + 'racket-sports' => __( 'Racket Sports', 'sportspress' ), + 'water-sports' => __( 'Water Sports', 'sportspress' ), + 'target-sports' => __( 'Target Sports', 'sportspress' ), + 'esports' => __( 'Esports', 'sportspress' ), + 'other' => __( 'Other', 'sportspress' ), + ) + ); } /** * Sport preset names for localization + * * @return null */ public static function sport_preset_names() { diff --git a/includes/admin/class-sp-admin-status.php b/includes/admin/class-sp-admin-status.php index 268c101c..e66f46a9 100644 --- a/includes/admin/class-sp-admin-status.php +++ b/includes/admin/class-sp-admin-status.php @@ -2,75 +2,78 @@ /** * Debug/Status page * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin * @version 1.4 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( ! class_exists( 'SP_Admin_Status' ) ) : -/** - * SP_Admin_Status Class - */ -class SP_Admin_Status { - /** - * Retrieve metadata from a file. Based on WP Core's get_file_data function - * - * @since 0.8 - * @param string $file Path to the file - * @param array $all_headers List of headers, in the format array('HeaderKey' => 'Header Name') + * SP_Admin_Status Class */ - public function get_file_version( $file ) { - // We don't need to write to the file, so just open for reading. - $fp = fopen( $file, 'r' ); + class SP_Admin_Status { - // Pull only the first 8kiB of the file in. - $file_data = fread( $fp, 8192 ); + /** + * Retrieve metadata from a file. Based on WP Core's get_file_data function + * + * @since 0.8 + * @param string $file Path to the file + * @param array $all_headers List of headers, in the format array('HeaderKey' => 'Header Name') + */ + public function get_file_version( $file ) { + // We don't need to write to the file, so just open for reading. + $fp = fopen( $file, 'r' ); - // PHP will close file handle, but we are good citizens. - fclose( $fp ); + // Pull only the first 8kiB of the file in. + $file_data = fread( $fp, 8192 ); - // Make sure we catch CR-only line endings. - $file_data = str_replace( "\r", "\n", $file_data ); - $version = ''; + // PHP will close file handle, but we are good citizens. + fclose( $fp ); - if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) - $version = _cleanup_header_comment( $match[1] ); + // Make sure we catch CR-only line endings. + $file_data = str_replace( "\r", "\n", $file_data ); + $version = ''; - return $version ; - } - - /** - * Scan the template files - * - * @access public - * @param string $template_path - * @return array - */ - public function scan_template_files( $template_path ) { - $files = scandir( $template_path ); - $result = array(); - if ( $files ) { - foreach ( $files as $key => $value ) { - if ( ! in_array( $value, array( ".",".." ) ) ) { - if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { - $sub_files = $this->scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); - foreach ( $sub_files as $sub_file ) { - $result[] = $value . DIRECTORY_SEPARATOR . $sub_file; + if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) { + $version = _cleanup_header_comment( $match[1] ); + } + + return $version; + } + + /** + * Scan the template files + * + * @access public + * @param string $template_path + * @return array + */ + public function scan_template_files( $template_path ) { + $files = scandir( $template_path ); + $result = array(); + if ( $files ) { + foreach ( $files as $key => $value ) { + if ( ! in_array( $value, array( '.', '..' ) ) ) { + if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { + $sub_files = $this->scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); + foreach ( $sub_files as $sub_file ) { + $result[] = $value . DIRECTORY_SEPARATOR . $sub_file; + } + } else { + $result[] = $value; } - } else { - $result[] = $value; } } } + return $result; } - return $result; } -} endif; diff --git a/includes/admin/class-sp-admin-taxonomies.php b/includes/admin/class-sp-admin-taxonomies.php index ec3aff8a..45070e2c 100644 --- a/includes/admin/class-sp-admin-taxonomies.php +++ b/includes/admin/class-sp-admin-taxonomies.php @@ -6,11 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) { /** * Handles taxonomies in admin * - * @class SP_Admin_Taxonomies - * @version 2.7.9 - * @package SportsPress/Admin - * @category Class - * @author ThemeBoy + * @class SP_Admin_Taxonomies + * @version 2.7.9 + * @package SportsPress/Admin + * @category Class + * @author ThemeBoy */ class SP_Admin_Taxonomies { @@ -71,7 +71,7 @@ class SP_Admin_Taxonomies { * @param mixed $term Term (category) being edited */ public function edit_taxonomy_fields( $term ) { - $t_id = $term->term_id; + $t_id = $term->term_id; ?> @@ -80,7 +80,7 @@ class SP_Admin_Taxonomies { - 'id', - 'order' => 'DESC', + 'orderby' => 'id', + 'order' => 'DESC', 'hide_empty' => false, - 'number' => 1, + 'number' => 1, ); // Get latitude and longitude from the last added venue $terms = get_terms( 'sp_venue', $args ); - if ( $terms && array_key_exists( 0, $terms) && is_object( reset( $terms ) ) ): - $term = reset( $terms ); - $t_id = $term->term_id; + if ( $terms && array_key_exists( 0, $terms ) && is_object( reset( $terms ) ) ) : + $term = reset( $terms ); + $t_id = $term->term_id; $term_meta = get_option( "taxonomy_$t_id" ); - $latitude = sp_array_value( $term_meta, 'sp_latitude', '-37.8165647' ); + $latitude = sp_array_value( $term_meta, 'sp_latitude', '-37.8165647' ); $longitude = sp_array_value( $term_meta, 'sp_longitude', '144.9475055' ); - $address = sp_array_value( $term_meta, 'sp_address', '' ); + $address = sp_array_value( $term_meta, 'sp_address', '' ); endif; // Sanitize latitude and longitude, fallback to default. - if( ! is_numeric( $latitude) || ! is_numeric( $longitude) ): - $latitude = '-37.8165647'; + if ( ! is_numeric( $latitude ) || ! is_numeric( $longitude ) ) : + $latitude = '-37.8165647'; $longitude = '144.9475055'; endif; ?> @@ -129,7 +129,7 @@ class SP_Admin_Taxonomies { - term_id; - $term_meta = get_option( "taxonomy_$t_id" ); - $latitude = is_numeric( $term_meta['sp_latitude'] ) ? $term_meta['sp_latitude'] : ''; + $t_id = $term->term_id; + $term_meta = get_option( "taxonomy_$t_id" ); + $latitude = is_numeric( $term_meta['sp_latitude'] ) ? $term_meta['sp_latitude'] : ''; $longitude = is_numeric( $term_meta['sp_longitude'] ) ? $term_meta['sp_longitude'] : ''; - $address = $term_meta['sp_address'] ? $term_meta['sp_address'] : ''; + $address = $term_meta['sp_address'] ? $term_meta['sp_address'] : ''; ?> @@ -170,7 +170,7 @@ class SP_Admin_Taxonomies { -
    - __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) ); - foreach ( $options as $key => $value ): + $options = apply_filters( + 'sportspress_performance_sections', + array( + 0 => __( 'Offense', 'sportspress' ), + 1 => __( + 'Defense', + 'sportspress' + ), + ) + ); + foreach ( $options as $key => $value ) : printf( '', $key, selected( true ), $value ); endforeach; ?>
    - term_id; + $t_id = $term->term_id; $sections = sp_get_term_sections( $t_id ); ?> - __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) ); - foreach ( $options as $key => $value ): + $options = apply_filters( + 'sportspress_performance_sections', + array( + 0 => __( 'Offense', 'sportspress' ), + 1 => __( + 'Defense', + 'sportspress' + ), + ) + ); + foreach ( $options as $key => $value ) : printf( '', $key, selected( in_array( $key, $sections ), true, false ), $value ); endforeach; ?> @@ -227,7 +253,7 @@ class SP_Admin_Taxonomies { - __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) ); + + $options = apply_filters( + 'sportspress_performance_sections', + array( + 0 => __( 'Offense', 'sportspress' ), + 1 => __( + 'Defense', + 'sportspress' + ), + ) + ); $sections = sp_get_term_sections( $id ); - + $section_names = array(); - + if ( is_array( $sections ) ) { foreach ( $sections as $section ) { if ( array_key_exists( $section, $options ) ) { @@ -355,7 +394,7 @@ class SP_Admin_Taxonomies { } } } - + $columns .= implode( ', ', $section_names ); } elseif ( $column == 'sp_order' ) { diff --git a/includes/admin/class-sp-admin-welcome.php b/includes/admin/class-sp-admin-welcome.php index db73e35a..47037a56 100644 --- a/includes/admin/class-sp-admin-welcome.php +++ b/includes/admin/class-sp-admin-welcome.php @@ -10,404 +10,447 @@ * @category Admin * @package SportsPress/Admin * @version 2.7.9 -*/ + */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} /** * SP_Admin_Welcome class. */ class SP_Admin_Welcome { - private $plugin; + private $plugin; - /** - * __construct function. - * - * @access public - * @return void - */ - public function __construct() { - $this->plugin = 'sportspress/sportspress.php'; + /** + * __construct function. + * + * @access public + * @return void + */ + public function __construct() { + $this->plugin = 'sportspress/sportspress.php'; - add_action( 'admin_menu', array( $this, 'admin_menus') ); - add_action( 'admin_head', array( $this, 'admin_head' ) ); - add_action( 'admin_init', array( $this, 'welcome' ) ); - } + add_action( 'admin_menu', array( $this, 'admin_menus' ) ); + add_action( 'admin_head', array( $this, 'admin_head' ) ); + add_action( 'admin_init', array( $this, 'welcome' ) ); + } - /** - * Add admin menus/screens - * - * @access public - * @return void - */ - public function admin_menus() { - if ( empty( $_GET['page'] ) ) { - return; - } + /** + * Add admin menus/screens + * + * @access public + * @return void + */ + public function admin_menus() { + if ( empty( $_GET['page'] ) ) { + return; + } - $welcome_page_name = __( 'About SportsPress', 'sportspress' ); - $welcome_page_title = __( 'Welcome to SportsPress', 'sportspress' ); + $welcome_page_name = __( 'About SportsPress', 'sportspress' ); + $welcome_page_title = __( 'Welcome to SportsPress', 'sportspress' ); - switch ( $_GET['page'] ) { - case 'sp-about' : - $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-about', array( $this, 'about_screen' ) ); - add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) ); - break; - case 'sp-credits' : - $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-credits', array( $this, 'credits_screen' ) ); - add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) ); - break; - case 'sp-translators' : - $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-translators', array( $this, 'translators_screen' ) ); - add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) ); - break; - } - } + switch ( $_GET['page'] ) { + case 'sp-about': + $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-about', array( $this, 'about_screen' ) ); + add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) ); + break; + case 'sp-credits': + $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-credits', array( $this, 'credits_screen' ) ); + add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) ); + break; + case 'sp-translators': + $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-translators', array( $this, 'translators_screen' ) ); + add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) ); + break; + } + } - /** - * admin_css function. - * - * @access public - * @return void - */ - public function admin_css() { - wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ), array(), SP_VERSION ); - } + /** + * admin_css function. + * + * @access public + * @return void + */ + public function admin_css() { + wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ), array(), SP_VERSION ); + } - /** - * Add styles just for this page, and remove dashboard page links. - * - * @access public - * @return void - */ - public function admin_head() { - remove_submenu_page( 'index.php', 'sp-about' ); - remove_submenu_page( 'index.php', 'sp-credits' ); - remove_submenu_page( 'index.php', 'sp-translators' ); - } + /** + * Add styles just for this page, and remove dashboard page links. + * + * @access public + * @return void + */ + public function admin_head() { + remove_submenu_page( 'index.php', 'sp-about' ); + remove_submenu_page( 'index.php', 'sp-credits' ); + remove_submenu_page( 'index.php', 'sp-translators' ); + } - /** - * Into text/links shown on all about pages. - * - * @access private - * @return void - */ - private function intro() { + /** + * Into text/links shown on all about pages. + * + * @access private + * @return void + */ + private function intro() { - // Flush after upgrades - if ( ! empty( $_GET['sp-updated'] ) || ! empty( $_GET['sp-installed'] ) ) - flush_rewrite_rules(); + // Flush after upgrades + if ( ! empty( $_GET['sp-updated'] ) || ! empty( $_GET['sp-installed'] ) ) { + flush_rewrite_rules(); + } - // Get major version number - $version = explode( '.', SP()->version, 3 ); - unset( $version[2] ); - $display_version = implode( '.', $version ); - ?> -

    ' ); ?>

    + // Get major version number + $version = explode( '.', SP()->version, 3 ); + unset( $version[2] ); + $display_version = implode( '.', $version ); + ?> +

    ' ); ?>

    -
    version ); ?>
    +
    version ); ?>
    -
    - + -
    + printf( __( '%1$s SportsPress %2$s has lots of refinements we think you’ll love.', 'sportspress' ), $message, $display_version ); + ?> + -

    - - - - -

    + + + + +

    - - + + + + + + + -
    + /** + * Output the about screen. + */ + public function about_screen() { + include_once 'class-sp-admin-settings.php'; + $class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' ); + ?> +
    - intro(); ?> + intro(); ?> - -
    -

    -
    - +
    +

    +
    + -
    -
    -

    New Features 🌟

    -
    -
    + do_action( 'sportspress_before_welcome_features' ); + ?> +
    +
    +

    New Features 🌟

    +
    +
    -
    -
    - Screenshot -

    Conditional Equations

    -

    Use the newly introduced conditional operators >, <, , , , and to calculate the relationship between variables, then insert that calculation into more complex equations. Visit the Configure page to edit variables and equations.

    -
    -
    - Screenshot -

    Event Specs

    -

    Measure and display additional details per event using the new Event Specs variables. They are customizable and can be useful for keeping track of information like player of the match, attendance, and venue weather. -

    -
    - Screenshot -

    Next Team Column

    -

    Provide a quick overview of who each team is playing next using the new Next Team preset for league table columns. This will automatically display the next team's name or logo that links to the next match for each team in the table.

    -

    -
    +
    +
    + Screenshot +

    Conditional Equations

    +

    Use the newly introduced conditional operators >, <, , , , and to calculate the relationship between variables, then insert that calculation into more complex equations. Visit the Configure page to edit variables and equations.

    +
    +
    + Screenshot +

    Event Specs

    +

    Measure and display additional details per event using the new Event Specs variables. They are customizable and can be useful for keeping track of information like player of the match, attendance, and venue weather. +

    +
    + Screenshot +

    Next Team Column

    +

    Provide a quick overview of who each team is playing next using the new Next Team preset for league table columns. This will automatically display the next team's name or logo that links to the next match for each team in the table.

    +

    +
    - -
    + +
    -
    -
    -

    SportsPress Pro Updates 🏆

    -
    -
    +
    +
    +

    SportsPress Pro Updates 🏆

    +
    +
    -
    -
    - Results Matrix -

    Results Matrix

    -

    Display matches between home and away team in a grid. Create or select an existing calendar and select the Matrix layout to convert the calendar to an interactive results matrix!

    -
    -
    - Midseason Transfers -

    Midseason Transfers

    -

    Keep track of players that switched teams during a season by adding one or more extra rows to their statistics table. Display the team and partial statistics before and after the transfer.

    -

    -
    - Vertical Timelines -

    Vertical Timelines

    -

    Display a match commentary style play-by-play timeline within events. Upgrade to SportsPress Pro to get access to Timelines and other pro features.

    -

    -
    +
    +
    + Results Matrix +

    Results Matrix

    +

    Display matches between home and away team in a grid. Create or select an existing calendar and select the Matrix layout to convert the calendar to an interactive results matrix!

    +
    +
    + Midseason Transfers +

    Midseason Transfers

    +

    Keep track of players that switched teams during a season by adding one or more extra rows to their statistics table. Display the team and partial statistics before and after the transfer.

    +

    +
    + Vertical Timelines +

    Vertical Timelines

    +

    Display a match commentary style play-by-play timeline within events. Upgrade to SportsPress Pro to get access to Timelines and other pro features.

    +

    +
    - + -

    - +

    + -
    +
    -
    -
    -

    Player Data Improvements

    -
    -
    +
    +
    +

    Player Data Improvements

    +
    +
    -
    -
    -

    Player Assignments

    -

    Players will now be saved using a new data format that allows them to belong to multiple leagues, seasons, and teams and be accurately selected in player lists.

    -
    -
    -

    Current Team Column

    -

    The Team column in player lists will now display only the current team that player belongs to, determined by the Current Team setting of each player.

    -
    -
    -

    Squad Number Zero

    -

    It's now possible to import players with the squad number 0 (zero) or any other value that would previously be interpreted as empty.

    -
    -
    +
    +
    +

    Player Assignments

    +

    Players will now be saved using a new data format that allows them to belong to multiple leagues, seasons, and teams and be accurately selected in player lists.

    +
    +
    +

    Current Team Column

    +

    The Team column in player lists will now display only the current team that player belongs to, determined by the Current Team setting of each player.

    +
    +
    +

    Squad Number Zero

    +

    It's now possible to import players with the squad number 0 (zero) or any other value that would previously be interpreted as empty.

    +
    +
    -
    +
    -
    -
    -

    Other Notes

    -
    -
    +
    +
    +

    Other Notes

    +
    +
    -
    -
    -

    Countdown Images

    -

    A new option has been added to the Countdown widget, allowing you to display a featured image from the next event.

    -
    -
    -

    Relative Date in Shortcodes

    -

    You'll now be able to select a relative date range when inserting calendar-related shortcodes from the visual editor.

    -
    -
    -

    Short Names

    -

    Teams have been given a Short Name setting in addition to the existing Abbreviation for added customizability.

    -
    -
    +
    +
    +

    Countdown Images

    +

    A new option has been added to the Countdown widget, allowing you to display a featured image from the next event.

    +
    +
    +

    Relative Date in Shortcodes

    +

    You'll now be able to select a relative date range when inserting calendar-related shortcodes from the visual editor.

    +
    +
    +

    Short Names

    +

    Teams have been given a Short Name setting in addition to the existing Abbreviation for added customizability.

    +
    +
    - + + +
    + 'sportspress', 'tab' => 'general' ), 'admin.php' ) ) ); ?>"> -
    - +
    + intro(); ?> + +

    Contribute to SportsPress.', 'sportspress' ), 'https://github.com/ThemeBoy/SportsPress/blob/master/CONTRIBUTING.md' ); ?>

    - /** - * Output the credits. - */ - public function credits_screen() { - ?> -
    - intro(); ?> - -

    Contribute to SportsPress.', 'sportspress' ), 'https://github.com/ThemeBoy/SportsPress/blob/master/CONTRIBUTING.md' ); ?>

    +
    + contributors() ); ?> +
    +
    + - contributors() ); ?> -
    - - +
    - /** - * Output the translators screen - */ - public function translators_screen() { - ?> -
    + intro(); ?> - intro(); ?> +

    Translate SportsPress.', 'sportspress' ), 'https://translate.wordpress.org/projects/wp-plugins/sportspress' ); ?>

    +
    + Translate SportsPress.', 'sportspress' ), 'https://translate.wordpress.org/projects/wp-plugins/sportspress' ); ?>

    -
    - get_contributors(); - /** - * Render Contributors List - * - * @access public - * @return string $contributor_list HTML formatted list of contributors. - */ - public function contributors() { - $contributors = $this->get_contributors(); + if ( empty( $contributors ) ) { + return ''; + } - if ( empty( $contributors ) ) { - return ''; - } + $contributor_list = ''; + return $contributor_list; + } - return $contributor_list; - } + /** + * Retrieve list of contributors from GitHub. + * + * @access public + * @return mixed + */ + public function get_contributors() { + $contributors = get_transient( 'sportspress_contributors' ); - /** - * Retrieve list of contributors from GitHub. - * - * @access public - * @return mixed - */ - public function get_contributors() { - $contributors = get_transient( 'sportspress_contributors' ); + if ( false !== $contributors ) { + return $contributors; + } - if ( false !== $contributors ) { - return $contributors; - } + $response = wp_remote_get( 'https://api.github.com/repos/ThemeBoy/SportsPress/contributors', array( 'sslverify' => false ) ); - $response = wp_remote_get( 'https://api.github.com/repos/ThemeBoy/SportsPress/contributors', array( 'sslverify' => false ) ); + if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { + return array(); + } - if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { - return array(); - } + $contributors = json_decode( wp_remote_retrieve_body( $response ) ); - $contributors = json_decode( wp_remote_retrieve_body( $response ) ); + if ( ! is_array( $contributors ) ) { + return array(); + } - if ( ! is_array( $contributors ) ) { - return array(); - } + set_transient( 'sportspress_contributors', $contributors, HOUR_IN_SECONDS ); - set_transient( 'sportspress_contributors', $contributors, HOUR_IN_SECONDS ); + return $contributors; + } - return $contributors; - } + /** + * Sends user to the welcome page on first activation + */ + public function welcome() { - /** - * Sends user to the welcome page on first activation - */ - public function welcome() { + // Bail if no activation redirect transient is set + if ( ! get_transient( '_sp_activation_redirect' ) ) { + return; + } - // Bail if no activation redirect transient is set - if ( ! get_transient( '_sp_activation_redirect' ) ) - return; + // Delete the redirect transient + delete_transient( '_sp_activation_redirect' ); - // Delete the redirect transient - delete_transient( '_sp_activation_redirect' ); + // Bail if we are waiting to install or update via the interface update/install links + if ( get_option( '_sp_needs_update' ) == 1 || get_option( '_sp_needs_pages' ) == 1 ) { + return; + } - // Bail if we are waiting to install or update via the interface update/install links - if ( get_option( '_sp_needs_update' ) == 1 || get_option( '_sp_needs_pages' ) == 1 ) - return; + // Bail if activating from network, or bulk, or within an iFrame + if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) { + return; + } - // Bail if activating from network, or bulk, or within an iFrame - if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) - return; + if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] ) && ( isset( $_GET['plugin'] ) && strstr( $_GET['plugin'], 'sportspress.php' ) ) ) { + return; + } - if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] ) && ( isset( $_GET['plugin'] ) && strstr( $_GET['plugin'], 'sportspress.php' ) ) ) - return; + if ( ! get_option( 'sportspress_completed_setup' ) ) { + wp_redirect( admin_url( 'admin.php?page=sp-setup' ) ); + exit; + } - if ( ! get_option( 'sportspress_completed_setup' ) ) { - wp_redirect( admin_url( 'admin.php?page=sp-setup' ) ); - exit; - } - - wp_redirect( admin_url( 'index.php?page=sp-about' ) ); - exit; - } + wp_redirect( admin_url( 'index.php?page=sp-about' ) ); + exit; + } } new SP_Admin_Welcome(); diff --git a/includes/admin/class-sp-admin.php b/includes/admin/class-sp-admin.php index a07a87d3..7d5d63bd 100644 --- a/includes/admin/class-sp-admin.php +++ b/includes/admin/class-sp-admin.php @@ -6,11 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) { /** * SportsPress Admin. * - * @class SP_Admin - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin - * @version 2.5.1 + * @class SP_Admin + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin + * @version 2.5.1 */ class SP_Admin { @@ -36,32 +36,32 @@ class SP_Admin { */ public function includes() { // Functions - include_once( 'sp-admin-functions.php' ); + include_once 'sp-admin-functions.php'; // Classes - include_once( 'class-sp-admin-post-types.php' ); - include_once( 'class-sp-admin-taxonomies.php' ); - include_once( 'class-sp-admin-ajax.php' ); + include_once 'class-sp-admin-post-types.php'; + include_once 'class-sp-admin-taxonomies.php'; + include_once 'class-sp-admin-ajax.php'; // Classes we only need if the ajax is not-ajax if ( ! is_ajax() ) { - include( 'class-sp-admin-menus.php' ); - include( 'class-sp-admin-welcome.php' ); - include( 'class-sp-admin-notices.php' ); - include( 'class-sp-admin-assets.php' ); - include( 'class-sp-admin-permalink-settings.php' ); + include 'class-sp-admin-menus.php'; + include 'class-sp-admin-welcome.php'; + include 'class-sp-admin-notices.php'; + include 'class-sp-admin-assets.php'; + include 'class-sp-admin-permalink-settings.php'; - if ( 'yes' == get_option( 'sportspress_rich_editing', 'yes' ) ): - include( 'class-sp-admin-editor.php' ); + if ( 'yes' == get_option( 'sportspress_rich_editing', 'yes' ) ) : + include 'class-sp-admin-editor.php'; endif; } // Setup/welcome if ( ! empty( $_GET['page'] ) ) { switch ( $_GET['page'] ) { - case 'sp-setup' : - include_once( 'class-sp-admin-setup-wizard.php' ); - break; + case 'sp-setup': + include_once 'class-sp-admin-setup-wizard.php'; + break; } } } @@ -73,8 +73,8 @@ class SP_Admin { $screen = get_current_screen(); switch ( $screen->id ) { - case 'dashboard' : - include( 'class-sp-admin-dashboard.php' ); + case 'dashboard': + include 'class-sp-admin-dashboard.php'; break; } } @@ -85,7 +85,7 @@ class SP_Admin { public function prevent_admin_access() { $prevent_access = false; - if ( 'yes' == get_option( 'sportspress_lock_down_admin' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_sportspress' ) ) && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) { + if ( 'yes' == get_option( 'sportspress_lock_down_admin' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_sportspress' ) ) && basename( $_SERVER['SCRIPT_FILENAME'] ) !== 'admin-post.php' ) { $prevent_access = true; } @@ -134,4 +134,4 @@ class SP_Admin { } } -return new SP_Admin(); \ No newline at end of file +return new SP_Admin(); diff --git a/includes/admin/importers/class-sp-event-importer.php b/includes/admin/importers/class-sp-event-importer.php index f68069e0..24fc46ce 100644 --- a/includes/admin/importers/class-sp-event-importer.php +++ b/includes/admin/importers/class-sp-event-importer.php @@ -2,13 +2,15 @@ /** * Event importer - import events into SportsPress. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin/Importers - * @version 2.7.9 + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin/Importers + * @version 2.7.9 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( class_exists( 'WP_Importer' ) ) { class SP_Event_Importer extends SP_Importer { @@ -20,20 +22,21 @@ if ( class_exists( 'WP_Importer' ) ) { * @return void */ public function __construct() { - $this->import_page = 'sp_event_csv'; + $this->import_page = 'sp_event_csv'; $this->import_label = __( 'Import Events', 'sportspress' ); - $this->columns = array( - 'post_date' => __( 'Date', 'sportspress' ), - 'post_time' => __( 'Time', 'sportspress' ), - 'sp_venue' => __( 'Venue', 'sportspress' ), - 'sp_team' => __( 'Teams', 'sportspress' ), + $this->columns = array( + 'post_date' => __( 'Date', 'sportspress' ), + 'post_time' => __( 'Time', 'sportspress' ), + 'sp_venue' => __( 'Venue', 'sportspress' ), + 'sp_team' => __( 'Teams', 'sportspress' ), 'sp_results' => __( 'Results', 'sportspress' ), 'sp_outcome' => __( 'Outcome', 'sportspress' ), - 'sp_player' => __( 'Players', 'sportspress' ), + 'sp_player' => __( 'Players', 'sportspress' ), ); $performance_labels = sp_get_var_labels( 'sp_performance' ); - if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) + if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) { $this->columns = array_merge( $this->columns, $performance_labels ); + } } /** @@ -47,7 +50,7 @@ if ( class_exists( 'WP_Importer' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) { $this->imported = $this->skipped = 0; - if ( ! is_array( $array ) || ! sizeof( $array ) ): + if ( ! is_array( $array ) || ! sizeof( $array ) ) : $this->footer(); die(); endif; @@ -56,29 +59,31 @@ if ( class_exists( 'WP_Importer' ) ) { // Get event format, league, and season from post vars $event_format = ( empty( $_POST['sp_format'] ) ? false : sanitize_text_field( $_POST['sp_format'] ) ); - $league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_league'] ) ); - $season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_season'] ) ); - $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) ); + $league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_league'] ) ); + $season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_season'] ) ); + $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) ); // Get labels from result and performance post types - $result_labels = sp_get_var_labels( 'sp_result' ); + $result_labels = sp_get_var_labels( 'sp_result' ); $performance_labels = sp_get_var_labels( 'sp_performance' ); - foreach ( $rows as $row ): + foreach ( $rows as $row ) : $row = array_filter( $row ); - if ( empty( $row ) ) continue; + if ( empty( $row ) ) { + continue; + } $meta = array(); - foreach ( $columns as $index => $key ): + foreach ( $columns as $index => $key ) : $meta[ $key ] = sp_array_value( $row, $index ); endforeach; // Slice array into event, team, and player - $event = array_slice( $row, 0, 3 ); - $team = array_slice( $row, 3, 3 ); + $event = array_slice( $row, 0, 3 ); + $team = array_slice( $row, 3, 3 ); $player = array_slice( $row, 6 ); // Get event details @@ -105,16 +110,16 @@ if ( class_exists( 'WP_Importer' ) ) { $player = array( sp_array_value( $meta, 'sp_player' ), ); - unset( $meta['sp_player' ] ); - foreach ( $performance_labels as $key => $label ): + unset( $meta['sp_player'] ); + foreach ( $performance_labels as $key => $label ) : $player[] = sp_array_value( $meta, $key, '' ); endforeach; // Add new event if date is given - if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ): + if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ) : // Add player performance to last event if available - if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ): + if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ) : update_post_meta( $id, 'sp_players', $players ); endif; @@ -122,9 +127,9 @@ if ( class_exists( 'WP_Importer' ) ) { list( $date, $time, $venue ) = $event; // Format date - $date = str_replace( '/', '-', trim( $date ) ); + $date = str_replace( '/', '-', trim( $date ) ); $date_array = explode( '-', $date ); - switch ( $date_format ): + switch ( $date_format ) : case 'dd/mm/yyyy': $date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . @@ -142,12 +147,17 @@ if ( class_exists( 'WP_Importer' ) ) { endswitch; // Add time to date if given - if ( ! empty( $time ) ): + if ( ! empty( $time ) ) : $date .= ' ' . trim( $time ); endif; // Define post type args - $args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date, 'post_title' => __( 'Event', 'sportspress' ) ); + $args = array( + 'post_type' => 'sp_event', + 'post_status' => 'publish', + 'post_date' => $date, + 'post_title' => __( 'Event', 'sportspress' ), + ); // Insert event $id = wp_insert_post( $args ); @@ -159,17 +169,17 @@ if ( class_exists( 'WP_Importer' ) ) { update_post_meta( $id, '_sp_import', 1 ); // Update event format - if ( $event_format ): + if ( $event_format ) : update_post_meta( $id, 'sp_format', $event_format ); endif; // Update league - if ( $league ): + if ( $league ) : wp_set_object_terms( $id, $league, 'sp_league', false ); endif; // Update season - if ( $season ): + if ( $season ) : wp_set_object_terms( $id, $season, 'sp_season', false ); endif; @@ -182,7 +192,7 @@ if ( class_exists( 'WP_Importer' ) ) { endif; // Add new team if team name is given - if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ): + if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ) : // List team columns list( $team_name, $result, $outcome ) = $team; @@ -191,20 +201,31 @@ if ( class_exists( 'WP_Importer' ) ) { $team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' ); // Get or insert team - if ( $team_object ): + if ( $team_object ) : // Make sure team is published - if ( $team_object->post_status != 'publish' ): - wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) ); + if ( $team_object->post_status != 'publish' ) : + wp_update_post( + array( + 'ID' => $team_object->ID, + 'post_status' => 'publish', + ) + ); endif; // Get team ID $team_id = $team_object->ID; - else: + else : // Insert team - $team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team_name ) ) ); + $team_id = wp_insert_post( + array( + 'post_type' => 'sp_team', + 'post_status' => 'publish', + 'post_title' => wp_strip_all_tags( $team_name ), + ) + ); // Flag as import update_post_meta( $team_id, '_sp_import', 1 ); @@ -212,17 +233,17 @@ if ( class_exists( 'WP_Importer' ) ) { endif; // Update league - if ( $league ): + if ( $league ) : wp_set_object_terms( $team_id, $league, 'sp_league', true ); endif; // Update season - if ( $season ): + if ( $season ) : wp_set_object_terms( $team_id, $season, 'sp_season', true ); endif; // Add to event if exists - if ( isset( $id ) ): + if ( isset( $id ) ) : // Add team to event add_post_meta( $id, 'sp_team', $team_id ); @@ -235,21 +256,21 @@ if ( class_exists( 'WP_Importer' ) ) { // Create team results array from result keys $team_results = array(); - if ( sizeof( $result_labels ) > 0 ): - foreach( $result_labels as $key => $label ): + if ( sizeof( $result_labels ) > 0 ) : + foreach ( $result_labels as $key => $label ) : $team_results[ $key ] = trim( array_shift( $results ) ); endforeach; - $team_results[ 'outcome' ] = array(); + $team_results['outcome'] = array(); endif; // Explode outcomes into array $outcomes = explode( '|', $outcome ); // Add outcome slugs to team outcomes array - foreach ( $outcomes as $outcome ): + foreach ( $outcomes as $outcome ) : // Continue if outcome doesn't exist - if ( $outcome == null ): + if ( $outcome == null ) : continue; endif; @@ -259,24 +280,35 @@ if ( class_exists( 'WP_Importer' ) ) { // Get or insert outcome $outcome_object = get_page_by_title( stripslashes( $outcome ), OBJECT, 'sp_outcome' ); - if ( $outcome_object ): + if ( $outcome_object ) : // Make sure outcome is published - if ( $outcome_object->post_status != 'publish' ): - wp_update_post( array( 'ID' => $outcome_object->ID, 'post_status' => 'publish' ) ); + if ( $outcome_object->post_status != 'publish' ) : + wp_update_post( + array( + 'ID' => $outcome_object->ID, + 'post_status' => 'publish', + ) + ); endif; // Get outcome slug $outcome_slug = $outcome_object->post_name; - else: + else : // Insert outcome - $outcome_id = wp_insert_post( array( 'post_type' => 'sp_outcome', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $outcome ) ) ); + $outcome_id = wp_insert_post( + array( + 'post_type' => 'sp_outcome', + 'post_status' => 'publish', + 'post_title' => wp_strip_all_tags( $outcome ), + ) + ); // Get outcome slug - $post_data = get_post( $outcome_id, ARRAY_A ); - $outcome_slug = $post_data['post_name']; + $post_data = get_post( $outcome_id, ARRAY_A ); + $outcome_slug = $post_data['post_name']; // Flag as import update_post_meta( $outcome_id, '_sp_import', 1 ); @@ -284,7 +316,7 @@ if ( class_exists( 'WP_Importer' ) ) { endif; // Add to team results array - $team_results[ 'outcome' ][] = $outcome_slug; + $team_results['outcome'][] = $outcome_slug; endforeach; @@ -292,7 +324,7 @@ if ( class_exists( 'WP_Importer' ) ) { $event_results = get_post_meta( $id, 'sp_results', true ); // Create new array if results not exists - if ( ! $event_results ): + if ( ! $event_results ) : $event_results = array(); endif; @@ -317,9 +349,9 @@ if ( class_exists( 'WP_Importer' ) ) { // Update event with new name $post = array( - 'ID' => $id, + 'ID' => $id, 'post_title' => $title, - 'post_name' => $id, + 'post_name' => $id, ); wp_update_post( $post ); @@ -328,7 +360,7 @@ if ( class_exists( 'WP_Importer' ) ) { endif; // Add new player if player name is given - if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ): + if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ) : // Get and unset player name leaving us with the performance $player_name = $player[0]; @@ -338,11 +370,16 @@ if ( class_exists( 'WP_Importer' ) ) { $player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' ); // Get or insert player - if ( $player_object ): + if ( $player_object ) : // Make sure player is published - if ( $player_object->post_status != 'publish' ): - wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) ); + if ( $player_object->post_status != 'publish' ) : + wp_update_post( + array( + 'ID' => $player_object->ID, + 'post_status' => 'publish', + ) + ); endif; // Get player ID @@ -351,10 +388,16 @@ if ( class_exists( 'WP_Importer' ) ) { // Get player number $player_number = get_post_meta( $player_id, 'sp_number', true ); - else: + else : // Insert player - $player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $player_name ) ) ); + $player_id = wp_insert_post( + array( + 'post_type' => 'sp_player', + 'post_status' => 'publish', + 'post_title' => wp_strip_all_tags( $player_name ), + ) + ); // Flag as import update_post_meta( $player_id, '_sp_import', 1 ); @@ -368,29 +411,29 @@ if ( class_exists( 'WP_Importer' ) ) { endif; // Update league - if ( $league ): + if ( $league ) : wp_set_object_terms( $player_id, $league, 'sp_league', true ); endif; // Update season - if ( $season ): + if ( $season ) : wp_set_object_terms( $player_id, $season, 'sp_season', true ); endif; // Add to event if exists - if ( isset( $id ) ): + if ( isset( $id ) ) : // Add player to event add_post_meta( $id, 'sp_player', $player_id ); // Add player performance to array if team is available - if ( isset( $team_id ) ): + if ( isset( $team_id ) ) : // Initialize performance array $performance = array( 'number' => $player_number ); // Map keys to player performance - foreach ( $performance_labels as $key => $label ): + foreach ( $performance_labels as $key => $label ) : $performance[ $key ] = array_shift( $player ); endforeach; $players[ $team_id ][ $player_id ] = $performance; @@ -398,17 +441,17 @@ if ( class_exists( 'WP_Importer' ) ) { // Get player teams $player_teams = get_post_meta( $player_id, 'sp_team', false ); $current_team = get_post_meta( $player_id, 'sp_current_team', true ); - $past_teams = get_post_meta( $player_id, 'sp_past_team', false ); + $past_teams = get_post_meta( $player_id, 'sp_past_team', false ); // Add team if not exists in player - if ( ! in_array( $team_id, $player_teams ) ): + if ( ! in_array( $team_id, $player_teams ) ) : add_post_meta( $player_id, 'sp_team', $team_id ); endif; // Add as past team or set current team if not set - if ( ! $current_team ): + if ( ! $current_team ) : update_post_meta( $player_id, 'sp_current_team', $team_id ); - elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ): + elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ) : add_post_meta( $player_id, 'sp_past_team', $team_id ); endif; @@ -421,13 +464,13 @@ if ( class_exists( 'WP_Importer' ) ) { endforeach; // Add player performance to last event if available - if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ): + if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ) : update_post_meta( $id, 'sp_players', $players ); endif; // Show Result echo '

    - '.sprintf( __( 'Import complete - imported %s events and skipped %s.', 'sportspress' ), $this->imported, $this->skipped ).' + ' . sprintf( __( 'Import complete - imported %1$s events and skipped %2$s.', 'sportspress' ), $this->imported, $this->skipped ) . '

    '; $this->import_end(); @@ -437,7 +480,7 @@ if ( class_exists( 'WP_Importer' ) ) { * Performs post-import cleanup of files and the cache */ function import_end() { - echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Events', 'sportspress' ) . '' . '

    '; + echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Events', 'sportspress' ) . '' . '

    '; do_action( 'import_end' ); } @@ -450,7 +493,7 @@ if ( class_exists( 'WP_Importer' ) ) { */ function greet() { echo '
    '; - echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'

    '; + echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '

    '; echo '

    ' . sprintf( __( 'Events need to be defined with columns in a specific order (3+ columns). Click here to download a sample.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/events-sample.csv' ) . '

    '; echo '

    ' . sprintf( __( 'Supports CSV files generated by LeagueLobster.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '

    '; wp_import_upload_form( 'admin.php?import=sp_event_csv&step=1' ); @@ -473,11 +516,11 @@ if ( class_exists( 'WP_Importer' ) ) {
      event as $name => $title ) { - ?> + foreach ( ( new SP_Formats() )->event as $name => $title ) { + ?>
    @@ -485,56 +528,60 @@ if ( class_exists( 'WP_Importer' ) ) {
    - + 'sp_league', - 'name' => 'sp_league', - 'values' => 'slug', + 'taxonomy' => 'sp_league', + 'name' => 'sp_league', + 'values' => 'slug', 'show_option_none' => __( '— Not set —', 'sportspress' ), ); - if ( ! sp_dropdown_taxonomies( $args ) ): + if ( ! sp_dropdown_taxonomies( $args ) ) : echo '

    ' . __( 'None', 'sportspress' ) . '

    '; sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) ); endif; - ?> + ?> +
    - + 'sp_season', - 'name' => 'sp_season', - 'values' => 'slug', + 'taxonomy' => 'sp_season', + 'name' => 'sp_season', + 'values' => 'slug', 'show_option_none' => __( '— Not set —', 'sportspress' ), ); - if ( ! sp_dropdown_taxonomies( $args ) ): + if ( ! sp_dropdown_taxonomies( $args ) ) : echo '

    ' . __( 'None', 'sportspress' ) . '

    '; sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) ); endif; - ?> + ?> + - -
    -
      + +
      +
      • - -
      • + +
      • - -
      • + +
      • - -
      • + +
      -
      - - - - +
    + + + + import_page = 'sp_event_performance_csv'; + $this->import_page = 'sp_event_performance_csv'; $this->import_label = __( 'Import Box Score', 'sportspress' ); - $this->columns = array( + $this->columns = array( 'sp_player' => __( 'Player', 'sportspress' ), ); $performance_labels = sp_get_var_labels( 'sp_performance' ); - if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) + if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) { $this->columns = array_merge( $this->columns, $performance_labels ); + } } /** @@ -41,7 +44,7 @@ if ( class_exists( 'WP_Importer' ) ) { function import( $array = array(), $columns = array( 'sp_player' ) ) { $this->imported = $this->skipped = 0; - if ( ! is_array( $array ) || ! sizeof( $array ) ): + if ( ! is_array( $array ) || ! sizeof( $array ) ) : $this->footer(); die(); endif; @@ -52,36 +55,44 @@ if ( class_exists( 'WP_Importer' ) ) { $event = ( empty( $_POST['sp_event'] ) ? false : sanitize_text_field( $_POST['sp_event'] ) ); $teams = ( empty( $_POST['sp_teams'] ) ? false : sanitize_text_field( $_POST['sp_teams'] ) ); $index = ( empty( $_POST['sp_index'] ) ? false : sanitize_text_field( $_POST['sp_index'] ) ); - $team = ( empty( $_POST['sp_team'] ) ? false : sanitize_text_field( $_POST['sp_team'] ) ); + $team = ( empty( $_POST['sp_team'] ) ? false : sanitize_text_field( $_POST['sp_team'] ) ); - $team_players = array( 0 ); + $team_players = array( 0 ); $team_performance = array(); - $name_index = (int) array_search( 'sp_player', $columns ); + $name_index = (int) array_search( 'sp_player', $columns ); - foreach ( $rows as $row ): + foreach ( $rows as $row ) : $row = array_filter( $row ); - if ( empty( $row ) ) continue; + if ( empty( $row ) ) { + continue; + } $player_name = sp_array_value( $row, $name_index ); - - if ( ! $player_name ): + + if ( ! $player_name ) : $this->skipped ++; continue; endif; $player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' ); - if ( $player_object ): + if ( $player_object ) : // Get player ID $player_id = $player_object->ID; - else: + else : // Insert player - $player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $player_name ) ) ); + $player_id = wp_insert_post( + array( + 'post_type' => 'sp_player', + 'post_status' => 'publish', + 'post_title' => wp_strip_all_tags( $player_name ), + ) + ); // Flag as import update_post_meta( $player_id, '_sp_import', 1 ); @@ -89,10 +100,12 @@ if ( class_exists( 'WP_Importer' ) ) { endif; $team_players[] = $player_id; - $player = array(); + $player = array(); - foreach ( $columns as $i => $key ): - if ( 'sp_player' === $key ) continue; + foreach ( $columns as $i => $key ) : + if ( 'sp_player' === $key ) { + continue; + } $player[ $key ] = sp_array_value( $row, $i, '' ); endforeach; @@ -100,13 +113,13 @@ if ( class_exists( 'WP_Importer' ) ) { endforeach; - if ( $event && $team ): + if ( $event && $team ) : $the_players = get_post_meta( $event, 'sp_player', false ); - $players = array(); - for ( $i = 0; $i < $teams; $i++ ): - if ( $index == $i ): + $players = array(); + for ( $i = 0; $i < $teams; $i++ ) : + if ( $index == $i ) : array_push( $players, $team_players ); - else: + else : array_push( $players, sp_array_between( $the_players, 0, $i ) ); endif; endfor; @@ -114,15 +127,15 @@ if ( class_exists( 'WP_Importer' ) ) { $this->imported = sizeof( $team_players ) - 1; - $performance = (array) get_post_meta( $event, 'sp_players', true ); - $performance = array_filter( $performance ); + $performance = (array) get_post_meta( $event, 'sp_players', true ); + $performance = array_filter( $performance ); $performance[ $team ] = $team_performance; update_post_meta( $event, 'sp_players', $performance ); endif; // Show Result echo '

    - '.sprintf( __( 'Import complete - imported %s rows and skipped %s.', 'sportspress' ), $this->imported, $this->skipped ).' + ' . sprintf( __( 'Import complete - imported %1$s rows and skipped %2$s.', 'sportspress' ), $this->imported, $this->skipped ) . '

    '; $this->import_end( $event ); @@ -132,7 +145,15 @@ if ( class_exists( 'WP_Importer' ) ) { * Performs post-import cleanup of files and the cache */ function import_end( $event = 0 ) { - echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Event', 'sportspress' ) . '' . '

    '; + echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Event', 'sportspress' ) . '' . '

    '; do_action( 'import_end' ); } @@ -149,8 +170,14 @@ if ( class_exists( 'WP_Importer' ) ) { echo '
    '; if ( $event ) { - $args = array_merge( $_REQUEST, array( 'import' => 'sp_event_performance_csv', 'step' => '1' ) ); - echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'

    '; + $args = array_merge( + $_REQUEST, + array( + 'import' => 'sp_event_performance_csv', + 'step' => '1', + ) + ); + echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '

    '; echo '

    ' . sprintf( __( 'Box scores need to be defined with columns in a specific order. Click here to download a sample.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/event-performance-sample.csv' ) . '

    '; wp_import_upload_form( add_query_arg( $args, 'admin.php' ) ); } else { @@ -167,10 +194,10 @@ if ( class_exists( 'WP_Importer' ) ) { * @return void */ function options() { - $event = sp_array_value( $_REQUEST, 'event', 0, 'key' ); - $teams = sp_array_value( $_REQUEST, 'teams', 0, 'key' ); - $index = sp_array_value( $_REQUEST, 'index', 0, 'key' ); - $team = sp_array_value( $_REQUEST, 'team', 0, 'key' ); + $event = sp_array_value( $_REQUEST, 'event', 0, 'key' ); + $teams = sp_array_value( $_REQUEST, 'teams', 0, 'key' ); + $index = sp_array_value( $_REQUEST, 'index', 0, 'key' ); + $team = sp_array_value( $_REQUEST, 'team', 0, 'key' ); $include = get_post_meta( $event, 'sp_team', false ); ?> @@ -192,10 +219,10 @@ if ( class_exists( 'WP_Importer' ) ) { 'sp_team', - 'name' => 'sp_team', - 'values' => 'ID', - 'selected' => $team, - 'include' => $include, + 'name' => 'sp_team', + 'values' => 'ID', + 'selected' => $team, + 'include' => $include, ); sp_dropdown_pages( $args ); ?> diff --git a/includes/admin/importers/class-sp-fixture-importer.php b/includes/admin/importers/class-sp-fixture-importer.php index 79be47bd..d823a7d3 100644 --- a/includes/admin/importers/class-sp-fixture-importer.php +++ b/includes/admin/importers/class-sp-fixture-importer.php @@ -2,13 +2,15 @@ /** * Fixture importer - import fixtures into SportsPress. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin/Importers - * @version 2.7 + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin/Importers + * @version 2.7 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( class_exists( 'WP_Importer' ) ) { class SP_Fixture_Importer extends SP_Importer { @@ -20,17 +22,17 @@ if ( class_exists( 'WP_Importer' ) ) { * @return void */ public function __construct() { - $this->import_page = 'sp_fixture_csv'; + $this->import_page = 'sp_fixture_csv'; $this->import_label = __( 'Import Fixtures', 'sportspress' ); - $this->columns = array( + $this->columns = array( 'post_date' => __( 'Date', 'sportspress' ), 'post_time' => __( 'Time', 'sportspress' ), - 'sp_venue' => __( 'Venue', 'sportspress' ), - 'sp_home' => __( 'Home', 'sportspress' ), - 'sp_away' => __( 'Away', 'sportspress' ), - 'sp_day' => __( 'Match Day', 'sportspress' ), + 'sp_venue' => __( 'Venue', 'sportspress' ), + 'sp_home' => __( 'Home', 'sportspress' ), + 'sp_away' => __( 'Away', 'sportspress' ), + 'sp_day' => __( 'Match Day', 'sportspress' ), ); - $this->optionals = array( 'sp_day' ); + $this->optionals = array( 'sp_day' ); } /** @@ -44,7 +46,7 @@ if ( class_exists( 'WP_Importer' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) { $this->imported = $this->skipped = 0; - if ( ! is_array( $array ) || ! sizeof( $array ) ): + if ( ! is_array( $array ) || ! sizeof( $array ) ) : $this->footer(); die(); endif; @@ -53,19 +55,21 @@ if ( class_exists( 'WP_Importer' ) ) { // Get event format, league, and season from post vars $event_format = ( empty( $_POST['sp_format'] ) ? false : $_POST['sp_format'] ); - $league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] ); - $season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] ); - $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] ); + $league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] ); + $season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] ); + $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] ); - foreach ( $rows as $row ): + foreach ( $rows as $row ) : $row = array_filter( $row ); - if ( empty( $row ) ) continue; + if ( empty( $row ) ) { + continue; + } $meta = array(); - foreach ( $columns as $index => $key ): + foreach ( $columns as $index => $key ) : $meta[ $key ] = sp_array_value( $row, $index ); endforeach; @@ -83,15 +87,15 @@ if ( class_exists( 'WP_Importer' ) ) { ); // Add new event if date is given - if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ): + if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ) : // List event columns list( $date, $time, $venue, $day ) = $event; // Format date - $date = str_replace( '/', '-', trim( $date ) ); + $date = str_replace( '/', '-', trim( $date ) ); $date_array = explode( '-', $date ); - switch ( $date_format ): + switch ( $date_format ) : case 'dd/mm/yyyy': $date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . @@ -109,12 +113,17 @@ if ( class_exists( 'WP_Importer' ) ) { endswitch; // Add time to date if given - if ( ! empty( $time ) ): + if ( ! empty( $time ) ) : $date .= ' ' . trim( $time ); endif; // Define post type args - $args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date, 'post_title' => __( 'Event', 'sportspress' ) ); + $args = array( + 'post_type' => 'sp_event', + 'post_status' => 'publish', + 'post_date' => $date, + 'post_title' => __( 'Event', 'sportspress' ), + ); // Insert event $id = wp_insert_post( $args ); @@ -123,25 +132,25 @@ if ( class_exists( 'WP_Importer' ) ) { update_post_meta( $id, '_sp_import', 1 ); // Update event format - if ( $event_format ): + if ( $event_format ) : update_post_meta( $id, 'sp_format', $event_format ); endif; // Update league - if ( $league ): + if ( $league ) : wp_set_object_terms( $id, $league, 'sp_league', false ); endif; // Update season - if ( $season ): + if ( $season ) : wp_set_object_terms( $id, $season, 'sp_season', false ); endif; // Update venue if ( $venue == '' ) { - $team = reset( $teams ); + $team = reset( $teams ); $team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' ); - $venue = sp_get_the_term_id( $team_object->ID, 'sp_venue' ); + $venue = sp_get_the_term_id( $team_object->ID, 'sp_venue' ); } wp_set_object_terms( $id, $venue, 'sp_venue', false ); @@ -156,30 +165,41 @@ if ( class_exists( 'WP_Importer' ) ) { endif; // Add teams to event - if ( sizeof( $teams ) > 0 ): + if ( sizeof( $teams ) > 0 ) : - foreach ( $teams as $team_name ): + foreach ( $teams as $team_name ) : - if ( '' !== $team_name ): + if ( '' !== $team_name ) : // Find out if team exists $team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' ); // Get or insert team - if ( $team_object ): + if ( $team_object ) : // Make sure team is published - if ( $team_object->post_status != 'publish' ): - wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) ); + if ( $team_object->post_status != 'publish' ) : + wp_update_post( + array( + 'ID' => $team_object->ID, + 'post_status' => 'publish', + ) + ); endif; // Get team ID $team_id = $team_object->ID; - else: + else : // Insert team - $team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team_name ) ) ); + $team_id = wp_insert_post( + array( + 'post_type' => 'sp_team', + 'post_status' => 'publish', + 'post_title' => wp_strip_all_tags( $team_name ), + ) + ); // Flag as import update_post_meta( $team_id, '_sp_import', 1 ); @@ -187,17 +207,17 @@ if ( class_exists( 'WP_Importer' ) ) { endif; // Update league - if ( $league ): + if ( $league ) : wp_set_object_terms( $team_id, $league, 'sp_league', true ); endif; // Update season - if ( $season ): + if ( $season ) : wp_set_object_terms( $team_id, $season, 'sp_season', true ); endif; // Add to event if exists - if ( isset( $id ) ): + if ( isset( $id ) ) : // Add team to event add_post_meta( $id, 'sp_team', $team_id ); @@ -217,19 +237,19 @@ if ( class_exists( 'WP_Importer' ) ) { // Update event with new name $post = array( - 'ID' => $id, + 'ID' => $id, 'post_title' => $title, - 'post_name' => $id, + 'post_name' => $id, ); wp_update_post( $post ); endif; - else: + else : // Add empty team to event add_post_meta( $id, 'sp_team', -1 ); - + endif; endforeach; @@ -240,7 +260,7 @@ if ( class_exists( 'WP_Importer' ) ) { // Show Result echo '

    - '.sprintf( __( 'Import complete - imported %s events and skipped %s.', 'sportspress' ), $this->imported, $this->skipped ).' + ' . sprintf( __( 'Import complete - imported %1$s events and skipped %2$s.', 'sportspress' ), $this->imported, $this->skipped ) . '

    '; $this->import_end(); @@ -250,7 +270,7 @@ if ( class_exists( 'WP_Importer' ) ) { * Performs post-import cleanup of files and the cache */ function import_end() { - echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Fixtures', 'sportspress' ) . '' . '

    '; + echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Fixtures', 'sportspress' ) . '' . '

    '; do_action( 'import_end' ); } @@ -263,7 +283,7 @@ if ( class_exists( 'WP_Importer' ) ) { */ function greet() { echo '
    '; - echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'

    '; + echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '

    '; echo '

    ' . sprintf( __( 'Fixtures need to be defined with columns in a specific order (4+ columns). Click here to download a sample.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/fixtures-sample.csv' ) . '

    '; echo '

    ' . sprintf( __( 'Supports CSV files generated by LeagueLobster.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '

    '; wp_import_upload_form( 'admin.php?import=sp_fixture_csv&step=1' ); @@ -293,56 +313,60 @@ if ( class_exists( 'WP_Importer' ) ) {
    - + ?> + - + ?> + - - - -

    + 'sp_league', - 'name' => 'sp_league', - 'values' => 'slug', + 'taxonomy' => 'sp_league', + 'name' => 'sp_league', + 'values' => 'slug', 'show_option_none' => __( '— Not set —', 'sportspress' ), ); - if ( ! sp_dropdown_taxonomies( $args ) ): + if ( ! sp_dropdown_taxonomies( $args ) ) : echo '

    ' . __( 'None', 'sportspress' ) . '

    '; sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) ); endif; - ?>

    + 'sp_season', - 'name' => 'sp_season', - 'values' => 'slug', + 'taxonomy' => 'sp_season', + 'name' => 'sp_season', + 'values' => 'slug', 'show_option_none' => __( '— Not set —', 'sportspress' ), ); - if ( ! sp_dropdown_taxonomies( $args ) ): + if ( ! sp_dropdown_taxonomies( $args ) ) : echo '

    ' . __( 'None', 'sportspress' ) . '

    '; sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) ); endif; - ?>
    -
    -
      +
    +
    +
    • - -
    • + +
    • - -
    • + +
    • - -
    • + +
    -
    -
    +
    + + + + plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true ); + wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true ); } /** @@ -46,32 +48,36 @@ if ( class_exists( 'WP_Importer' ) ) { function dispatch() { $this->header(); - if ( ! empty( $_POST['delimiter'] ) ) + if ( ! empty( $_POST['delimiter'] ) ) { $this->delimiter = stripslashes( trim( sanitize_text_field( $_POST['delimiter'] ) ) ); + } - if ( ! $this->delimiter ) + if ( ! $this->delimiter ) { $this->delimiter = ','; + } $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step']; - switch ( $step ): + switch ( $step ) : case 0: $this->greet(); break; case 1: check_admin_referer( 'import-upload' ); - if ( $this->handle_upload() ): + if ( $this->handle_upload() ) : - if ( $this->id ) + if ( $this->id ) { $file = get_attached_file( $this->id ); - else + } else { $file = ABSPATH . $this->file_url; + } add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) ); - if ( function_exists( 'gc_enable' ) ) + if ( function_exists( 'gc_enable' ) ) { gc_enable(); + } - @set_time_limit(0); + @set_time_limit( 0 ); @ob_flush(); @flush(); @@ -80,7 +86,7 @@ if ( class_exists( 'WP_Importer' ) ) { break; case 2: check_admin_referer( 'import-upload' ); - if ( isset( $_POST['sp_import'] ) ): + if ( isset( $_POST['sp_import'] ) ) : $columns = array_filter( sp_array_value( $_POST, 'sp_columns', array( 'post_title' ) ) ); $this->import( $_POST['sp_import'], array_values( $columns ) ); endif; @@ -100,7 +106,7 @@ if ( class_exists( 'WP_Importer' ) ) { ?> @@ -119,26 +125,26 @@ if ( class_exists( 'WP_Importer' ) ) { $this->imported = $this->skipped = 0; - if ( ! is_file($file) ): + if ( ! is_file( $file ) ) : $this->footer(); die(); endif; ini_set( 'auto_detect_line_endings', '1' ); - if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ): + if ( ( $handle = fopen( $file, 'r' ) ) !== false ) : $header = fgetcsv( $handle, 0, $this->delimiter ); - if ( sizeof( $header ) >= 1 ): + if ( sizeof( $header ) >= 1 ) : $action = 'admin.php?import=' . $this->import_page . '&step=2'; ?> -
    + options(); ?> - columns as $key => $label ): ?> + columns as $key => $label ) : ?> @@ -149,21 +155,35 @@ if ( class_exists( 'WP_Importer' ) ) { - delimiter ) ) !== FALSE ): ?> + delimiter ) ) !== false ) : ?> - columns as $key => $label ): $value = sp_array_value( $row, $index ); ?> + columns as $key => $label ) : + $value = sp_array_value( $row, $index ); + ?> - + - imported++; endwhile; ?> + imported++; +endwhile; + ?> - columns as $key => $label ): ?> + columns as $key => $label ) : ?> @@ -172,17 +192,17 @@ if ( class_exists( 'WP_Importer' ) ) { - +
    dropdown( $key ); ?>
    - optionals ) ) { ?> placeholder=""> + optionals ) ) { + ?> + placeholder="">

    - imported+1, $this->imported+1 ); ?> + imported + 1, $this->imported + 1 ); ?>

    ' . __( 'Sorry, there has been an error.', 'sportspress' ) . '
    '; _e( 'The CSV is invalid.', 'sportspress' ) . '

    '; @@ -191,7 +211,7 @@ if ( class_exists( 'WP_Importer' ) ) { endif; - fclose( $handle ); + fclose( $handle ); endif; } @@ -199,7 +219,7 @@ if ( class_exists( 'WP_Importer' ) ) { * format_data_from_csv function. * * @access public - * @param mixed $data + * @param mixed $data * @param string $enc * @return string */ @@ -239,7 +259,6 @@ if ( class_exists( 'WP_Importer' ) ) { return false; } - } return true; @@ -276,6 +295,7 @@ if ( class_exists( 'WP_Importer' ) ) { /** * Added to http_request_timeout filter to force timeout at 60 seconds during import + * * @param int $val * @return int 60 */ diff --git a/includes/admin/importers/class-sp-official-importer.php b/includes/admin/importers/class-sp-official-importer.php index 200fd52b..2f3dcf59 100644 --- a/includes/admin/importers/class-sp-official-importer.php +++ b/includes/admin/importers/class-sp-official-importer.php @@ -2,13 +2,15 @@ /** * Official importer - import officials into SportsPress. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin/Importers - * @version 2.5.1 + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin/Importers + * @version 2.5.1 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( class_exists( 'WP_Importer' ) ) { class SP_Official_Importer extends SP_Importer { @@ -20,9 +22,9 @@ if ( class_exists( 'WP_Importer' ) ) { * @return void */ public function __construct() { - $this->import_page = 'sp_official_csv'; + $this->import_page = 'sp_official_csv'; $this->import_label = __( 'Import Officials', 'sportspress' ); - $this->columns = array( + $this->columns = array( 'post_title' => __( 'Name', 'sportspress' ), ); parent::__construct(); @@ -39,33 +41,39 @@ if ( class_exists( 'WP_Importer' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) { $this->imported = $this->skipped = 0; - if ( ! is_array( $array ) || ! sizeof( $array ) ): + if ( ! is_array( $array ) || ! sizeof( $array ) ) : $this->footer(); die(); endif; $rows = array_chunk( $array, sizeof( $columns ) ); - foreach ( $rows as $row ): + foreach ( $rows as $row ) : $row = array_filter( $row ); - if ( empty( $row ) ) continue; + if ( empty( $row ) ) { + continue; + } $meta = array(); - foreach ( $columns as $index => $key ): + foreach ( $columns as $index => $key ) : $meta[ $key ] = sp_array_value( $row, $index ); endforeach; $name = sp_array_value( $meta, 'post_title' ); - if ( ! $name ): + if ( ! $name ) : $this->skipped++; continue; endif; - $args = array( 'post_type' => 'sp_official', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) ); + $args = array( + 'post_type' => 'sp_official', + 'post_status' => 'publish', + 'post_title' => wp_strip_all_tags( $name ), + ); $id = wp_insert_post( $args ); @@ -75,7 +83,7 @@ if ( class_exists( 'WP_Importer' ) ) { // Show Result echo '

    - '.sprintf( __( 'Import complete - imported %s officials and skipped %s.', 'sportspress' ), $this->imported, $this->skipped ).' + ' . sprintf( __( 'Import complete - imported %1$s officials and skipped %2$s.', 'sportspress' ), $this->imported, $this->skipped ) . '

    '; $this->import_end(); @@ -85,7 +93,7 @@ if ( class_exists( 'WP_Importer' ) ) { * Performs post-import cleanup of files and the cache */ function import_end() { - echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Officials', 'sportspress' ) . '' . '

    '; + echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Officials', 'sportspress' ) . '' . '

    '; do_action( 'import_end' ); } @@ -108,7 +116,7 @@ if ( class_exists( 'WP_Importer' ) ) { */ function greet() { echo '
    '; - echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'

    '; + echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '

    '; echo '

    ' . sprintf( __( 'Officials need to be defined with columns in a specific order. Click here to download a sample.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/officials-sample.csv' ) . '

    '; wp_import_upload_form( 'admin.php?import=sp_official_csv&step=1' ); echo '
    '; diff --git a/includes/admin/importers/class-sp-player-importer.php b/includes/admin/importers/class-sp-player-importer.php index 84875868..9b0baac4 100644 --- a/includes/admin/importers/class-sp-player-importer.php +++ b/includes/admin/importers/class-sp-player-importer.php @@ -2,13 +2,15 @@ /** * Player importer - import players into SportsPress. * - * @author ThemeBoy - * @category Admin - * @package SportsPress/Admin/Importers + * @author ThemeBoy + * @category Admin + * @package SportsPress/Admin/Importers * @version 2.7 */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; // Exit if accessed directly +} if ( class_exists( 'WP_Importer' ) ) { class SP_Player_Importer extends SP_Importer { @@ -20,17 +22,17 @@ if ( class_exists( 'WP_Importer' ) ) { * @return void */ public function __construct() { - $this->import_page = 'sp_player_csv'; + $this->import_page = 'sp_player_csv'; $this->import_label = __( 'Import Players', 'sportspress' ); - $this->columns = array( - 'sp_number' => __( 'Squad Number', 'sportspress' ), - 'post_title' => __( 'Name', 'sportspress' ), - 'sp_position' => __( 'Positions', 'sportspress' ), - 'sp_team' => __( 'Teams', 'sportspress' ), - 'sp_league' => __( 'Leagues', 'sportspress' ), - 'sp_season' => __( 'Seasons', 'sportspress' ), + $this->columns = array( + 'sp_number' => __( 'Squad Number', 'sportspress' ), + 'post_title' => __( 'Name', 'sportspress' ), + 'sp_position' => __( 'Positions', 'sportspress' ), + 'sp_team' => __( 'Teams', 'sportspress' ), + 'sp_league' => __( 'Leagues', 'sportspress' ), + 'sp_season' => __( 'Seasons', 'sportspress' ), 'sp_nationality' => __( 'Nationality', 'sportspress' ), - 'post_date' => __( 'Date of Birth', 'sportspress' ), + 'post_date' => __( 'Date of Birth', 'sportspress' ), ); parent::__construct(); } @@ -46,21 +48,23 @@ if ( class_exists( 'WP_Importer' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) { $this->imported = $this->skipped = 0; - if ( ! is_array( $array ) || ! sizeof( $array ) ): + if ( ! is_array( $array ) || ! sizeof( $array ) ) : $this->footer(); die(); endif; $rows = array_chunk( $array, sizeof( $columns ) ); - + // Get Date of Birth format from post vars $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) ); - foreach ( $rows as $row ): + foreach ( $rows as $row ) : $row = array_filter( $row, 'strlen' ); - if ( empty( $row ) ) continue; + if ( empty( $row ) ) { + continue; + } $meta = array(); @@ -76,17 +80,17 @@ if ( class_exists( 'WP_Importer' ) ) { $meta[ $p ] = ''; } - foreach ( $columns as $index => $key ): + foreach ( $columns as $index => $key ) : $meta[ $key ] = sp_array_value( $row, $index ); endforeach; $name = sp_array_value( $meta, 'post_title' ); $date = sp_array_value( $meta, 'post_date' ); - + // Format date of birth - $date = str_replace( '/', '-', trim( $date ) ); + $date = str_replace( '/', '-', trim( $date ) ); $date_array = explode( '-', $date ); - switch ( $date_format ): + switch ( $date_format ) : case 'dd/mm/yyyy': $date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . @@ -103,28 +107,37 @@ if ( class_exists( 'WP_Importer' ) ) { substr( str_pad( sp_array_value( $date_array, 2, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ); endswitch; - if ( ! $name ): + if ( ! $name ) : $this->skipped++; continue; endif; // Get or insert player $player_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_player' ) : false; - if ( $player_object ): - if ( $player_object->post_status != 'publish' ): - wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) ); + if ( $player_object ) : + if ( $player_object->post_status != 'publish' ) : + wp_update_post( + array( + 'ID' => $player_object->ID, + 'post_status' => 'publish', + ) + ); endif; $id = $player_object->ID; // Handle preservable data. foreach ( $preservable_metas_keys as $p ) { - $terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) ); + $terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) ); $meta[ $p ] .= '|' . implode( '|', $terms ); } - else: - $args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) ); + else : + $args = array( + 'post_type' => 'sp_player', + 'post_status' => 'publish', + 'post_title' => wp_strip_all_tags( $name ), + ); // Check if a DoB was set - if( '0000-00-00' !== $date ){ - $args['post_date'] = $date; + if ( '0000-00-00' !== $date ) { + $args['post_date'] = $date; } $id = wp_insert_post( $args ); @@ -148,18 +161,29 @@ if ( class_exists( 'WP_Importer' ) ) { wp_set_object_terms( $id, $seasons, 'sp_season', false ); // Update teams - $teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) ); - $i = 0; - foreach ( $teams as $team ): + $teams = (array) explode( '|', sp_array_value( $meta, 'sp_team' ) ); + $i = 0; + foreach ( $teams as $team ) : // Get or insert team $team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' ); - if ( $team_object ): - if ( $team_object->post_status != 'publish' ): - wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) ); + if ( $team_object ) : + if ( $team_object->post_status != 'publish' ) : + wp_update_post( + array( + 'ID' => $team_object->ID, + 'post_status' => 'publish', + ) + ); endif; $team_id = $team_object->ID; - else: - $team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team ) ) ); + else : + $team_id = wp_insert_post( + array( + 'post_type' => 'sp_team', + 'post_status' => 'publish', + 'post_title' => wp_strip_all_tags( $team ), + ) + ); // Flag as import update_post_meta( $team_id, '_sp_import', 1 ); wp_set_object_terms( $team_id, $leagues, 'sp_league', false ); @@ -170,7 +194,7 @@ if ( class_exists( 'WP_Importer' ) ) { add_post_meta( $id, 'sp_team', $team_id ); // Update current team if first in array, otherwise use as past team - if ( $i == 0 ): + if ( $i == 0 ) : update_post_meta( $id, 'sp_current_team', $team_id ); else : add_post_meta( $id, 'sp_past_team', $team_id ); @@ -181,7 +205,9 @@ if ( class_exists( 'WP_Importer' ) ) { // Update nationality $nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) ); - if ( $nationality == '*' ) $nationality = ''; + if ( $nationality == '*' ) { + $nationality = ''; + } update_post_meta( $id, 'sp_nationality', $nationality ); $this->imported++; @@ -190,7 +216,7 @@ if ( class_exists( 'WP_Importer' ) ) { // Show Result echo '

    - '.sprintf( __( 'Import complete - imported %s players and skipped %s.', 'sportspress' ), $this->imported, $this->skipped ).' + ' . sprintf( __( 'Import complete - imported %1$s players and skipped %2$s.', 'sportspress' ), $this->imported, $this->skipped ) . '

    '; $this->import_end(); @@ -200,7 +226,7 @@ if ( class_exists( 'WP_Importer' ) ) { * Performs post-import cleanup of files and the cache */ function import_end() { - echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Players', 'sportspress' ) . '' . '

    '; + echo '

    ' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Players', 'sportspress' ) . '' . '

    '; do_action( 'import_end' ); } @@ -223,7 +249,7 @@ if ( class_exists( 'WP_Importer' ) ) { */ function greet() { echo '
    '; - echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'

    '; + echo '

    ' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '

    '; echo '

    ' . sprintf( __( 'Players need to be defined with columns in a specific order (8 columns). Click here to download a sample.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/players-sample.csv' ) . '

    '; wp_import_upload_form( 'admin.php?import=sp_player_csv&step=1' ); echo '
    '; @@ -243,22 +269,22 @@ if ( class_exists( 'WP_Importer' ) ) { - -
    -
      + +
      +
      • - -
      • + +
      • - -
      • + +
      • - -
      • + +
      -
      - - +
    + +