/** * Get players. */ public function get_players() { check_ajax_referer('sp-get-players', 'nonce'); $team = sp_array_value($_POST, 'team'); $league = sp_array_value($_POST, 'league'); $season = sp_array_value($_POST, 'season'); $index = sp_array_value($_POST, 'index', 1); $selected = sp_array_value($_POST, 'selected', array()); $args = array('orderby' => 'menu_order'); if ($team) { $args['meta_query'] = array(array('key' => 'sp_current_team', 'value' => sp_array_value($_POST, 'team'))); } if ($league || $season) { $args['tax_query'] = array('relation' => 'AND'); if ($league) { $args['tax_query'][] = array('taxonomy' => 'sp_league', 'field' => 'id', 'terms' => $league); } if ($season) { $args['tax_query'][] = array('taxonomy' => 'sp_season', 'field' => 'id', 'terms' => $season); } } $player_args = $args; $player_args['meta_key'] = 'sp_number'; $player_args['orderby'] = 'meta_value_num'; $player_args['order'] = 'ASC'; $players = sp_get_posts('sp_player', $player_args); $staff = sp_get_posts('sp_staff', $args); $data = array('index' => $index); foreach ($players as $key => $value) { $players[$key]->post_title = sp_get_player_name_with_number($value->ID); } $data['players'] = $players; $data['staff'] = $staff; wp_send_json_success($data); }
/** * Define our custom columns shown in admin. * @param string $column */ public function custom_columns($column, $post_id) { switch ($column) { case 'sp_player': $players = array_filter(get_post_meta($post_id, 'sp_player')); echo sizeof($players); break; case 'sp_league': echo get_the_terms($post_id, 'sp_league') ? the_terms($post_id, 'sp_league') : __('All', 'prosports'); break; case 'sp_season': echo get_the_terms($post_id, 'sp_season') ? the_terms($post_id, 'sp_season') : __('All', 'prosports'); break; case 'sp_team': $teams = (array) get_post_meta($post_id, 'sp_team', false); $teams = array_filter($teams); if (empty($teams)) { echo __('All', 'prosports'); } else { foreach ($teams as $team_id) { if (!$team_id) { continue; } $team = get_post($team_id); if ($team) { echo $team->post_title . '<br>'; } } } break; case 'sp_layout': echo sp_array_value(SP()->formats->list, get_post_meta($post_id, 'sp_format', true), '—'); break; } }
/** * import function. * * @access public * @param array $array * @param array $columns * @return void */ function import($array = array(), $columns = array('post_title')) { $this->imported = $this->skipped = 0; if (!is_array($array) || !sizeof($array)) { $this->footer(); die; } $rows = array_chunk($array, sizeof($columns)); foreach ($rows as $row) { $row = array_filter($row); if (empty($row)) { continue; } $meta = array(); foreach ($columns as $index => $key) { $meta[$key] = sp_array_value($row, $index); } $name = sp_array_value($meta, 'post_title'); if (!$name) { $this->skipped++; continue; } $args = array('post_type' => 'sp_sponsor', 'post_status' => 'publish', 'post_title' => $name); $id = wp_insert_post($args); // Update URL update_post_meta($id, 'sp_url', sp_array_value($meta, 'sp_url')); $this->imported++; } // Show Result echo '<div class="updated settings-error below-h2"><p> ' . sprintf(__('Import complete - imported <strong>%s</strong> sponsors and skipped <strong>%s</strong>.', 'prosports'), $this->imported, $this->skipped) . ' </p></div>'; $this->import_end(); }
/** * Output the metabox */ public static function output($post) { $feeds = new SP_Feeds(); $calendar_feeds = $feeds->calendar; ?> <div> <?php foreach ($calendar_feeds as $slug => $formats) { ?> <?php $link = add_query_arg('feed', 'sp-' . $slug, untrailingslashit(get_post_permalink($post))); ?> <?php foreach ($formats as $format) { ?> <?php $protocol = sp_array_value($format, 'protocol'); if ($protocol) { $feed = str_replace(array('http:', 'https:'), 'webcal:', $link); } else { $feed = $link; } $prefix = sp_array_value($format, 'prefix'); if ($prefix) { $feed = $prefix . urlencode($feed); } ?> <p> <strong><?php echo sp_array_value($format, 'name'); ?> </strong> <a class="sp-link" href="<?php echo $feed; ?> " target="_blank" title="<?php _e('Link', 'sportspress'); ?> "></a> </p> <p> <input type="text" value="<?php echo $feed; ?> " readonly="readonly" class="code widefat"> </p> <?php } ?> <?php } ?> </div> <?php }
/** * Save settings */ public function save() { $settings = $this->get_settings(); SP_Admin_Settings::save_fields($settings); update_option('sportspress_header_sponsor_width', (int) sp_array_value($_POST, 'sportspress_header_sponsor_width', 128)); update_option('sportspress_header_sponsor_height', (int) sp_array_value($_POST, 'sportspress_header_sponsor_height', 64)); update_option('sportspress_header_sponsors_top', (int) sp_array_value($_POST, 'sportspress_header_sponsors_top', 10)); update_option('sportspress_header_sponsors_right', (int) sp_array_value($_POST, 'sportspress_header_sponsors_right', 10)); update_option('sportspress_footer_sponsor_width', (int) sp_array_value($_POST, 'sportspress_footer_sponsor_width', 256)); update_option('sportspress_footer_sponsor_height', (int) sp_array_value($_POST, 'sportspress_footer_sponsor_height', 128)); }
/** * Save event results inline. * * @since 1.5 */ function save_inline_results() { check_ajax_referer('sp-save-inline-results', 'nonce'); $id = sp_array_value($_POST, 'post_id'); $results = sp_array_value($_POST, 'results'); if (sp_update_main_results($id, $results)) { wp_send_json_success(); } else { wp_send_json_error(); } }
/** * Save meta box data */ public static function save($post_id, $post) { update_post_meta($post_id, 'sp_minutes', sp_array_value($_POST, 'sp_minutes', get_option('sportspress_event_minutes', 90))); $venues = array_filter(sp_array_value(sp_array_value($_POST, 'tax_input', array()), 'sp_venue', array())); if (empty($venues)) { $teams = sp_array_value($_POST, 'sp_team', array()); $team = reset($teams); $venue = sp_get_the_term_id($team, 'sp_venue'); wp_set_post_terms($post_id, $venue, 'sp_venue'); } }
/** * Auto-generate an event title based on the team playing if left blank. * * @param array $data * @return array */ public function wp_insert_post_data($data, $postarr) { if ($data['post_type'] == 'sp_event' && $data['post_title'] == '') { $teams = sp_array_value($postarr, 'sp_team', array()); $team_names = array(); foreach ($teams as $team) { $team_names[] = get_the_title($team); } $data['post_title'] = implode(' ' . get_option('prosports_event_teams_delimiter', 'vs') . ' ', $team_names); } return $data; }
/** * Get settings array * * @return array */ public function get_settings() { $settings = array(array('title' => __('Text', 'prosports'), 'type' => 'title', 'desc' => __('The following options affect how words are displayed on the frontend.', 'prosports'), 'id' => 'text_options')); $strings = sp_get_text_options(); $options = get_option('prosports_text'); foreach ($strings as $string) { $settings[] = array('title' => $string, 'id' => 'prosports_text[' . $string . ']', 'default' => '', 'placeholder' => $string, 'value' => sp_array_value($options, $string, null), 'type' => 'text'); } $settings[] = array('type' => 'sectionend', 'id' => 'text_options'); return apply_filters('prosports_text_settings', $settings); // End event settings }
/** * Add venue fields. * * @access public * @return void */ public function add_venue_fields() { $args = array('orderby' => 'id', 'order' => 'DESC', 'hide_empty' => false, '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; $term_meta = get_option("taxonomy_{$t_id}"); $latitude = sp_array_value($term_meta, 'sp_latitude', '40.7324319'); $longitude = sp_array_value($term_meta, 'sp_longitude', '-73.82480799999996'); } else { $latitude = '40.7324319'; $longitude = '-73.82480799999996'; } ?> <div class="form-field"> <label for="term_meta[sp_address]"><?php _e('Address', 'sportspress'); ?> </label> <input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value=""> <p><div class="sp-location-picker"></div></p> <p><?php _e("Drag the marker to the venue's location.", 'sportspress'); ?> </p> </div> <div class="form-field"> <label for="term_meta[sp_latitude]"><?php _e('Latitude', 'sportspress'); ?> </label> <input type="text" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo esc_attr($latitude); ?> "> </div> <div class="form-field"> <label for="term_meta[sp_longitude]"><?php _e('Longitude', 'sportspress'); ?> </label> <input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr($longitude); ?> "> </div> <?php }
/** * Save meta box data */ public static function save($post_id, $post) { update_post_meta($post_id, 'sp_minutes', sp_array_value($_POST, 'sp_minutes', get_option('prosports_event_minutes', 90))); $taxonomies = apply_filters('prosports_event_taxonomies', array('sp_league' => null, 'sp_season' => null, 'sp_venue' => 'sp_event')); foreach ($taxonomies as $taxonomy => $post_type) { $value = sp_array_value($_POST, $taxonomy, -1); if (0 == $value) { $teams = sp_array_value($_POST, 'sp_team', array()); $team = reset($teams); $value = sp_get_the_term_id($team, $taxonomy); } wp_set_post_terms($post_id, $value, $taxonomy); update_post_meta($post_id, $taxonomy, $value); } }
/** * Define our custom columns shown in admin. * @param string $column */ public function custom_columns($column, $post_id) { switch ($column) { case 'sp_league': echo get_the_terms($post_id, 'sp_league') ? the_terms($post_id, 'sp_league') : __('All', 'sportspress'); break; case 'sp_season': echo get_the_terms($post_id, 'sp_season') ? the_terms($post_id, 'sp_season') : __('All', 'sportspress'); break; case 'sp_rounds': echo get_post_meta($post_id, 'sp_rounds', true); break; case 'sp_layout': echo sp_array_value(SP()->formats->tournament, get_post_meta($post_id, 'sp_format', true), '—'); break; } }
public static function delete_duplicate(&$post) { global $wpdb; $key = isset($post['sp_key']) ? $post['sp_key'] : null; if (!$key) { $key = $post['post_title']; } $id = sp_array_value($post, 'post_ID', 'var'); $title = sp_get_eos_safe_slug($key, $id); $check_sql = "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $title, $post['post_type'], $id)); if ($post_name_check) { wp_delete_post($post_name_check, true); $post['post_status'] = 'draft'; } return $post_name_check; }
/** * import function. * * @access public * @param array $array * @param array $columns * @return void */ function import($array = array(), $columns = array('post_title')) { $this->imported = $this->skipped = 0; if (!is_array($array) || !sizeof($array)) { $this->footer(); die; } $rows = array_chunk($array, sizeof($columns)); foreach ($rows as $row) { $row = array_filter($row); if (empty($row)) { continue; } $meta = array(); foreach ($columns as $index => $key) { $meta[$key] = sp_array_value($row, $index); } $name = sp_array_value($meta, 'post_title'); if (!$name) { $this->skipped++; continue; } $args = array('post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $name); $id = wp_insert_post($args); // Flag as import update_post_meta($id, '_sp_import', 1); // Update leagues $leagues = explode('|', sp_array_value($meta, 'sp_league')); wp_set_object_terms($id, $leagues, 'sp_league', false); // Update seasons $seasons = explode('|', sp_array_value($meta, 'sp_season')); wp_set_object_terms($id, $seasons, 'sp_season', false); // Update venues $venues = explode('|', sp_array_value($meta, 'sp_venue')); wp_set_object_terms($id, $venues, 'sp_venue', false); // Update meta update_post_meta($id, 'sp_url', sp_array_value($meta, 'sp_url')); update_post_meta($id, 'sp_abbreviation', sp_array_value($meta, 'sp_abbreviation')); $this->imported++; } // Show Result echo '<div class="updated settings-error below-h2"><p> ' . sprintf(__('Import complete - imported <strong>%s</strong> teams and skipped <strong>%s</strong>.', 'sportspress'), $this->imported, $this->skipped) . ' </p></div>'; $this->import_end(); }
/** * Auto-generate an event title based on the team playing if left blank. * * @param array $data * @return array */ public function wp_insert_post_data($data, $postarr) { if ($data['post_type'] == 'sp_event' && $data['post_title'] == '') { $teams = sp_array_value($postarr, 'sp_team', array()); $teams = array_filter($teams); $team_names = array(); foreach ($teams as $team) { while (is_array($team)) { $team = array_shift(array_filter($team)); } if ($team > 0) { $team_names[] = get_the_title($team); } } $team_names = array_unique($team_names); $data['post_title'] = implode(' ' . get_option('sportspress_event_teams_delimiter', 'vs') . ' ', $team_names); } return $data; }
/** * Save settings */ public function save() { $settings = $this->get_settings(); SP_Admin_Settings::save_fields($settings); if (isset($_POST['sportspress_league_menu_teams'])) { $teams = $_POST['sportspress_league_menu_teams']; } else { $teams = array(); } update_option('sportspress_league_menu_teams', $teams); if (isset($_POST['sp_league_menu_logo_removed'])) { delete_option('sportspress_league_menu_logo'); } update_option('sportspress_league_menu_logo_width', sp_array_value($_POST, 'sportspress_league_menu_logo_width', 64)); update_option('sportspress_league_menu_logo_height', sp_array_value($_POST, 'sportspress_league_menu_logo_height', 32)); update_option('sportspress_league_menu_logo_bottom', sp_array_value($_POST, 'sportspress_league_menu_logo_bottom', 0)); update_option('sportspress_league_menu_logo_left', sp_array_value($_POST, 'sportspress_league_menu_logo_left', 0)); update_option('sportspress_league_menu_team_width', sp_array_value($_POST, 'sportspress_league_menu_team_width', 32)); update_option('sportspress_league_menu_team_height', sp_array_value($_POST, 'sportspress_league_menu_team_height', 32)); }
/** * Output the about screen. */ public function about_screen() { include_once 'class-sp-admin-settings.php'; $class = 'chosen-select' . (is_rtl() ? ' chosen-rtl' : ''); ?> <div class="wrap about-wrap about-sportspress-wrap"> <?php $this->intro(); ?> <?php // Save settings if (isset($_POST['timezone_string'])) { update_option('timezone_string', $_POST['timezone_string']); update_option('sportspress_basic_setup', 1); } if (isset($_POST['sportspress_sport']) && !empty($_POST['sportspress_sport'])) { $sport = $_POST['sportspress_sport']; SP_Admin_Sports::apply_preset($sport); update_option('sportspress_sport', $_POST['sportspress_sport']); update_option('_sportspress_needs_welcome', 1); ?> <div id="message" class="updated sportspress-message"> <p><strong><?php _e('Your settings have been saved.', 'sportspress'); ?> </strong></p> </div> <?php } if (isset($_POST['add_sample_data'])) { SP_Admin_Sample_Data::delete_posts(); SP_Admin_Sample_Data::insert_posts(); } ?> <div class="sp-feature feature-section col two-col"> <div> <?php if (get_option('sportspress_basic_setup')) { ?> <h4><?php _e('Sport', 'sportspress'); ?> </h4> <?php $sport = get_option('sportspress_sport'); $sport_options = SP_Admin_Sports::get_preset_options(); foreach ($sport_options as $options) { foreach ($options as $slug => $name) { if ($sport === $slug) { $sport = $name; break; } } } echo $sport; ?> <a href="<?php echo esc_url(admin_url(add_query_arg(array('page' => 'sportspress', 'tab' => 'general'), 'admin.php'))); ?> "><i class="dashicons dashicons-edit"></i> <?php _e('Change', 'sportspress'); ?> </a> <h4><?php _e('Next Steps', 'sportspress'); ?> </h4> <p><?php _e('We’ve assembled some links to get you started:', 'sportspress'); ?> </p> <?php $steps = apply_filters('sportspress_next_steps', array('teams' => array('link' => admin_url(add_query_arg(array('post_type' => 'sp_team'), 'edit.php')), 'icon' => 'sp-icon-shield', 'label' => __('Add New Team', 'sportspress')), 'players' => array('link' => admin_url(add_query_arg(array('post_type' => 'sp_player'), 'edit.php')), 'icon' => 'sp-icon-tshirt', 'label' => __('Add New Player', 'sportspress')), 'events' => array('link' => admin_url(add_query_arg(array('post_type' => 'sp_event'), 'edit.php')), 'icon' => 'sp-icon-calendar', 'label' => __('Add New Event', 'sportspress')))); ?> <?php if (sizeof($steps)) { ?> <div class="sportspress-steps"> <ul> <?php foreach ($steps as $step) { ?> <li><a href="<?php echo esc_url($step['link']); ?> " class="welcome-icon sp-welcome-icon"><i class="<?php echo sp_array_value($step, 'icon'); ?> "></i> <?php echo $step['label']; ?> </a></li> <?php } ?> </ul> </div> <?php } ?> <h4><?php _e('Settings', 'sportspress'); ?> </h4> <a href="<?php echo esc_url(admin_url(add_query_arg(array('page' => 'sportspress', 'tab' => 'general'), 'admin.php'))); ?> "><?php _e('Go to SportsPress Settings', 'sportspress'); ?> </a> <?php } else { ?> <form method="post" id="mainform" action="" enctype="multipart/form-data"> <h4><?php _e('Basic Setup', 'sportspress'); ?> </h4> <p><?php _e('Select your timezone and sport to get started.', 'sportspress'); ?> </p> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row" class="titledesc"> <label for="timezone_string"><?php _e('Timezone', 'sportspress'); ?> <i class="dashicons dashicons-editor-help sp-desc-tip" title="<?php _e('Choose a city in the same timezone as you.', 'sportspress'); ?> "></i></label> </th> <td> <select id="timezone_string" name="timezone_string" class="<?php echo $class; ?> "> <?php $current_offset = get_option('gmt_offset'); $tzstring = get_option('timezone_string'); $check_zone_info = true; // Remove old Etc mappings. Fallback to gmt_offset. if (false !== strpos($tzstring, 'Etc/GMT')) { $tzstring = ''; } if (empty($tzstring)) { // Create a UTC+- zone if no timezone string exists $check_zone_info = false; if (0 == $current_offset) { $tzstring = 'UTC+0'; } elseif ($current_offset < 0) { $tzstring = 'UTC' . $current_offset; } else { $tzstring = 'UTC+' . $current_offset; } } echo wp_timezone_choice($tzstring); ?> </select> </td> </tr> <?php $sport_options = SP_Admin_Sports::get_preset_options(); $settings = array(array('id' => 'sportspress_sport', 'default' => 'custom', 'type' => 'sport', 'title' => __('Sport', 'sportspress'), 'welcome' => true, 'class' => $class, 'options' => $sport_options)); SP_Admin_Settings::output_fields($settings); ?> </tbody> </table> <p class="submit sportspress-actions"> <input name="save" class="button-primary" type="submit" value="<?php _e('Save Changes', 'sportspress'); ?> " /> <input type="hidden" name="subtab" id="last_tab" /> <?php wp_nonce_field('sportspress-settings'); ?> </p> </form> <?php } ?> </div> <?php if (current_user_can('install_themes') && !current_theme_supports('sportspress')) { ?> <div class="last-feature"> <h4><?php _e('Free SportsPress Theme', 'sportspress'); ?> </h4> <a href="<?php echo add_query_arg(array('theme' => 'rookie'), network_admin_url('theme-install.php')); ?> " class="sp-theme-screenshot"><img src="<?php echo plugin_dir_url(SP_PLUGIN_FILE); ?> /assets/images/modules/rookie.png"></a> <p><?php _e('Have you tried the free Rookie theme yet?', 'sportspress'); ?> </p> <p><?php _e('Rookie is a free starter theme for SportsPress designed by ThemeBoy.', 'sportspress'); ?> </p> <p class="sp-module-actions"> <a class="button button-large" href="<?php echo add_query_arg(array('theme' => 'rookie'), network_admin_url('theme-install.php')); ?> "><?php _e('Install Now', 'sportspress'); ?> </a> </p> </div> <?php } ?> </div> </div> <?php }
/** * Output admin fields. * * Loops though the prosports 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'] = ''; } // Custom attribute handling $custom_attributes = array(); 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 = ''; } if ($description && in_array($value['type'], array('textarea', 'radio'))) { $description = '<p style="margin-top:0">' . wp_kses_post($description) . '</p>'; } elseif ($description && in_array($value['type'], array('checkbox'))) { $description = wp_kses_post($description); } elseif ($description) { $description = '<span class="description">' . wp_kses_post($description) . '</span>'; } if ($tip && in_array($value['type'], array('checkbox'))) { $tip = '<p class="description">' . $tip . '</p>'; } elseif ($tip) { $tip = '<img class="help_tip" data-tip="' . esc_attr($tip) . '" src="' . SP()->plugin_url() . '/assets/images/help.png" height="16" width="16" />'; } // Switch based on type switch ($value['type']) { // Section Titles case 'title': if (!empty($value['title'])) { echo '<h3>' . esc_html($value['title']) . '</h3>'; } if (!empty($value['desc'])) { echo wpautop(wptexturize(wp_kses_post($value['desc']))); } echo '<table class="form-table">' . "\n\n"; if (!empty($value['id'])) { do_action('prosports_settings_' . sanitize_title($value['id'])); } break; // Section Ends // Section Ends case 'sectionend': if (!empty($value['id'])) { do_action('prosports_settings_' . sanitize_title($value['id']) . '_end'); } echo '</table>'; if (!empty($value['id'])) { do_action('prosports_settings_' . sanitize_title($value['id']) . '_after'); } break; // Standard text inputs and subtypes like 'number' // 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 .= '<div id="colorPickerDiv_' . esc_attr($value['id']) . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>'; } ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <input name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " type="<?php echo esc_attr($type); ?> " style="<?php echo esc_attr($value['css']); ?> " value="<?php echo esc_attr($option_value); ?> " placeholder="<?php echo esc_attr($value['placeholder']); ?> " class="<?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> /> <?php echo $description; ?> </td> </tr><?php break; // Textarea // Textarea case 'textarea': $option_value = self::get_option($value['id'], $value['default']); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <?php echo $description; ?> <textarea name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " style="<?php echo esc_attr($value['css']); ?> " class="<?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> ><?php echo esc_textarea($option_value); ?> </textarea> </td> </tr><?php break; // Select boxes // Select boxes case 'select': case 'multiselect': $option_value = self::get_option($value['id'], $value['default']); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <select name="<?php echo esc_attr($value['id']); if ($value['type'] == 'multiselect') { echo '[]'; } ?> " id="<?php echo esc_attr($value['id']); ?> " style="<?php echo esc_attr($value['css']); ?> " class="chosen-select<?php if (is_rtl()) { ?> chosen-rtl<?php } ?> <?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> <?php if ($value['type'] == 'multiselect') { echo 'multiple="multiple"'; } ?> > <?php foreach ($value['options'] as $key => $val) { ?> <option value="<?php echo esc_attr($key); ?> " <?php if (is_array($option_value)) { selected(in_array($key, $option_value), true); } else { selected($option_value, $key); } ?> ><?php echo $val; ?> </option> <?php } ?> </select> <?php echo $description; ?> </td> </tr><?php break; // Select boxes with optgroup // Select boxes with optgroup case 'groupselect': $option_value = self::get_option($value['id'], $value['default']); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <select name="<?php echo esc_attr($value['id']); if ($value['type'] == 'multiselect') { echo '[]'; } ?> " id="<?php echo esc_attr($value['id']); ?> " style="<?php echo esc_attr($value['css']); ?> " class="chosen-select<?php if (is_rtl()) { ?> chosen-rtl<?php } ?> <?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> <?php if ($value['type'] == 'multiselect') { echo 'multiple="multiple"'; } ?> > <?php foreach ($value['options'] as $group => $options) { ?> <optgroup label="<?php _e($group, 'prosports'); ?> "> <?php foreach ($options as $key => $val) { ?> <option value="<?php echo esc_attr($key); ?> " <?php if (is_array($option_value)) { selected(in_array($key, $option_value), true); } else { selected($option_value, $key); } ?> ><?php echo $val; ?> </option> <?php } ?> </optgroup> <?php } ?> </select> <?php echo $description; ?> </td> </tr><?php break; // Select sport // Select sport case 'sport': $option_value = self::get_option($value['id'], $value['default']); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <select name="<?php echo esc_attr($value['id']); if ($value['type'] == 'multiselect') { echo '[]'; } ?> " id="<?php echo esc_attr($value['id']); ?> " style="<?php echo esc_attr($value['css']); ?> " class="chosen-select<?php if (is_rtl()) { ?> chosen-rtl<?php } ?> <?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> <?php if ($value['type'] == 'multiselect') { echo 'multiple="multiple"'; } ?> > <?php foreach ($value['options'] as $group => $options) { ?> <optgroup label="<?php _e($group, 'prosports'); ?> "> <?php foreach ($options as $key => $val) { ?> <option value="<?php echo esc_attr($key); ?> " <?php if (is_array($option_value)) { selected(in_array($key, $option_value), true); } else { selected($option_value, $key); } ?> ><?php echo $val; ?> </option> <?php } ?> </optgroup> <?php } ?> </select> <?php echo $description; ?> <p> <label> <input type="checkbox" name="add_sample_data" id="add_sample_data" <?php checked(sp_array_value($value, 'welcome')); ?> > <?php _e('Install demo content', 'prosports'); ?> </label> </p> </td> </tr><?php break; // Radio inputs // Radio inputs case 'radio': $option_value = self::get_option($value['id'], $value['default']); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($value['id']); ?> "><?php echo esc_html($value['title']); ?> </label> <?php echo $tip; ?> </th> <td class="forminp forminp-<?php echo sanitize_title($value['type']); ?> "> <fieldset> <?php echo $description; ?> <ul> <?php foreach ($value['options'] as $key => $val) { ?> <li> <label><input name="<?php echo esc_attr($value['id']); ?> " value="<?php echo $key; ?> " type="radio" style="<?php echo esc_attr($value['css']); ?> " class="<?php echo esc_attr($value['class']); ?> " <?php echo implode(' ', $custom_attributes); ?> <?php checked($key, $option_value); ?> /> <?php echo $val; ?> </label> </li> <?php } ?> </ul> </fieldset> </td> </tr><?php break; // Checkbox input // Checkbox input case 'checkbox': $option_value = self::get_option($value['id'], $value['default']); $visbility_class = array(); if (!isset($value['hide_if_checked'])) { $value['hide_if_checked'] = false; } if (!isset($value['show_if_checked'])) { $value['show_if_checked'] = false; } if ($value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes') { $visbility_class[] = 'hidden_option'; } if ($value['hide_if_checked'] == 'option') { $visbility_class[] = 'hide_options_if_checked'; } if ($value['show_if_checked'] == 'option') { $visbility_class[] = 'show_options_if_checked'; } if (!isset($value['checkboxgroup']) || 'start' == $value['checkboxgroup']) { ?> <tr valign="top" class="<?php echo esc_attr(implode(' ', $visbility_class)); ?> "> <th scope="row" class="titledesc"><?php echo esc_html($value['title']); ?> </th> <td class="forminp forminp-checkbox"> <fieldset> <?php } else { ?> <fieldset class="<?php echo esc_attr(implode(' ', $visbility_class)); ?> "> <?php } if (!empty($value['title'])) { ?> <legend class="screen-reader-text"><span><?php echo esc_html($value['title']); ?> </span></legend> <?php } ?> <label for="<?php echo $value['id']; ?> "> <input name="<?php echo esc_attr($value['id']); ?> " id="<?php echo esc_attr($value['id']); ?> " type="checkbox" value="1" <?php checked($option_value, 'yes'); ?> <?php echo implode(' ', $custom_attributes); ?> /> <?php echo $description; ?> </label> <?php echo $tip; ?> <?php if (!isset($value['checkboxgroup']) || 'end' == $value['checkboxgroup']) { ?> </fieldset> </td> </tr> <?php } else { ?> </fieldset> <?php } break; // Default: run an action // Default: run an action default: do_action('prosports_admin_field_' . $value['type'], $value); break; } } }
} $output .= '<td class="data-name' . $name_class . '">' . $name . '</td>'; if (array_key_exists('team', $labels)) { $team = sp_array_value($row, 'team', get_post_meta($id, 'sp_team', true)); $team_name = get_the_title($team); if ($link_teams) { $team_name = '<a href="' . get_post_permalink($team) . '">' . $team_name . '</a>'; } $output .= '<td class="data-team">' . $team_name . '</td>'; } foreach ($labels as $key => $value) { if (in_array($key, array('number', 'name', 'team'))) { continue; } if (!is_array($columns) || in_array($key, $columns)) { $output .= '<td class="data-' . $key . '">' . sp_array_value($row, $key, '—') . '</td>'; } } $output .= '</tr>'; $i++; } } $output .= '</tbody>' . '</table>' . '</div>'; } if ($show_all_players_link) { $output .= '<a class="sp-player-list-link sp-view-all-link" href="' . get_permalink($id) . '">' . __('View all players', 'prosports') . '</a>'; } ?> <div class="sp-template sp-template-player-list"> <?php echo $output;
/** * Save meta box data */ public static function save($post_id, $post) { self::delete_duplicate($_POST); update_post_meta($post_id, 'sp_section', (int) sp_array_value($_POST, 'sp_section', -1)); update_post_meta($post_id, 'sp_precision', (int) sp_array_value($_POST, 'sp_precision', 1)); update_post_meta($post_id, 'sp_visible', sp_array_value($_POST, 'sp_visible', 1)); }
if (in_array($key, array('number', 'name'))) { continue; } if ($key == 'position') { $value = '—'; } elseif ($primary && $key !== $primary) { $value = ' '; } elseif (array_key_exists($key, $row) && $row[$key] != '') { $value = $row[$key]; } else { $value = sp_array_value($totals, $key, 0); } if ($mode == 'values') { echo '<td class="data-' . $key . '">' . $value . '</td>'; } elseif (intval($value) && $mode == 'icons') { $performance_id = sp_array_value($performance_ids, $key, null); $icons = ''; if ($performance_id && has_post_thumbnail($performance_id)) { $icons = str_repeat(get_the_post_thumbnail($performance_id, 'sportspress-fit-mini') . ' ', $value); } echo apply_filters('sportspress_event_performance_icons', $icons, $performance_id, $value); } } if ($mode == 'icons') { echo '</td>'; } ?> </tr> <?php } ?>
/** * Save meta box data */ public static function save($post_id, $post) { update_post_meta($post_id, 'sp_format', sp_array_value($_POST, 'sp_format', 'list')); }
/** * Admin edit table */ public static function table($labels = array(), $data = null, $rounds = 3, $rows = 23, $post_id = null) { $args = array('post_type' => 'sp_event', 'posts_per_page' => -1, 'post_status' => 'any', 'meta_key' => 'sp_format', 'meta_value' => 'tournament', 'tax_query' => array()); // Filter by league if selected $league_id = sp_get_the_term_id($post_id, 'sp_league', 0); if ($league_id) { $args['tax_query'][] = array('taxonomy' => 'sp_league', 'field' => 'id', 'terms' => $league_id); } // Filter by season if selected $season_id = sp_get_the_term_id($post_id, 'sp_season', 0); if ($season_id) { $args['tax_query'][] = array('taxonomy' => 'sp_season', 'field' => 'id', 'terms' => $season_id); } // Get events $posts = get_posts($args); ?> <table class="widefat sp-tournament-container"> <thead> <tr> <?php for ($round = 0; $round < $rounds; $round++) { ?> <th> <input type="text" class="widefat" name="sp_labels[]" value="<?php echo sp_array_value($labels, $round, ''); ?> " placeholder="<?php printf(__('Round %s', 'prosports'), $round + 1); ?> "> </th> <?php } ?> </tr> </thead> <tbody> <?php for ($row = 0; $row < $rows; $row++) { ?> <tr> <?php for ($round = 0; $round < $rounds; $round++) { $cell = sp_array_value(sp_array_value($data, $row, array()), $round, null); if ($cell === null) { continue; } $index = sp_array_value($cell, 'index'); $event = sp_array_value($cell, 'event', 0); if (sp_array_value($cell, 'type', null) === 'event') { echo '<td rowspan="' . sp_array_value($cell, 'rows', 1) . '" class="sp-event' . ($round === 0 ? ' sp-first-round' : '') . ($round === $rounds - 1 ? ' sp-last-round' : '') . '">'; echo '<select class="postform sp-event-selector" name="sp_event[' . $index . ']" data-event="' . $index . '">'; echo '<option value="0" data-home="" data-away="">' . sprintf(__('Select %s', 'prosports'), __('Event', 'prosports')) . '</option>'; foreach ($posts as $post) { $teams = get_post_meta($post->ID, 'sp_team'); $home = array_shift($teams); $away = array_shift($teams); echo '<option value="' . $post->ID . '" data-home="' . get_the_title($home) . '" data-away="' . get_the_title($away) . '"' . selected($event, $post->ID) . '>' . date_i18n(get_option('date_format')) . ' — ' . $post->post_title . '</option>'; } echo '</select>'; echo '</td>'; } elseif (sp_array_value($cell, 'type', null) === 'team') { echo '<td rowspan="' . sp_array_value($cell, 'rows', 1) . '" class="sp-team' . ($round === 0 ? ' sp-first-round' : '') . ($round === $rounds - 1 ? ' sp-last-round' : '') . '"> <input type="text" readonly="readonly" class="widefat sp-team-display" data-event="' . $index . '"> </td>'; } else { echo '<td rowspan="' . sp_array_value($cell, 'rows', 1) . '"> </td>'; } } ?> </tr> <?php } ?> </tbody> </table> <?php }
/** * Save meta box data */ public static function save($post_id, $post) { sp_update_post_meta_recursive($post_id, 'sp_staff', sp_array_value($_POST, 'sp_staff', array())); }
function sp_sort_table_teams($a, $b) { global $sportspress_column_priorities; // Loop through priorities foreach ($sportspress_column_priorities as $priority) { // Proceed if columns are not equal if (sp_array_value($a, $priority['column'], 0) != sp_array_value($b, $priority['column'], 0)) { // Compare column values $output = sp_array_value($a, $priority['column'], 0) - sp_array_value($b, $priority['column'], 0); // Flip value if descending order if ($priority['order'] == 'DESC') { $output = 0 - $output; } return $output > 0; } } // Default sort by alphabetical return strcmp(sp_array_value($a, 'name', ''), sp_array_value($b, 'name', '')); }
/** * Save meta box data */ public static function save($post_id, $post) { update_post_meta($post_id, 'sp_metrics', sp_array_value($_POST, 'sp_metrics', array())); }
function sp_get_position_caption($term = 0) { $meta = get_option("taxonomy_{$term}"); $caption = sp_array_value($meta, 'sp_caption', ''); if ($caption) { return $caption; } else { $term = get_term($term, 'sp_position'); return $term->name; } }
$teams_array = array(); $team_logos = array(); if ($teams) { foreach ($teams as $team) { $name = get_the_title($team); if ($name) { if ($show_team_logo) { $name = sp_get_logo($team, 'mini') . ' ' . $name; $team_logos[] = sp_get_logo($team, 'mini'); } if ($link_teams) { $team_output = '<a href="' . get_post_permalink($team) . '">' . $name . '</a>'; } else { $team_output = $name; } $team_result = sp_array_value($main_results, $team, null); if ($team_result != null) { if ($usecolumns != null && !in_array('time', $usecolumns)) { $team_output .= ' (' . $team_result . ')'; } } $teams_array[] = $team_output; $teams_output .= $team_output . '<br>'; } } } else { $teams_output .= '—'; } echo '<tr class="sp-row sp-post' . ($i % 2 == 0 ? ' alternate' : '') . '">'; echo '<td class="data-date"><a href="' . get_permalink($event->ID) . '"><date>' . get_post_time('Y-m-d H:i:s', false, $event) . '</date>' . get_post_time(get_option('date_format'), false, $event, true) . '</a></td>'; switch ($title_format) {
/** * import function. * * @access public * @param array $array * @param array $columns * @return void */ function import($array = array(), $columns = array('post_title')) { $this->imported = $this->skipped = 0; if (!is_array($array) || !sizeof($array)) { $this->footer(); die; } $rows = array_chunk($array, sizeof($columns)); foreach ($rows as $row) { $row = array_filter($row); if (empty($row)) { continue; } $meta = array(); foreach ($columns as $index => $key) { $meta[$key] = sp_array_value($row, $index); } $name = sp_array_value($meta, 'post_title'); if (!$name) { $this->skipped++; continue; } $args = array('post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => $name); $id = wp_insert_post($args); // Flag as import update_post_meta($id, '_sp_import', 1); // Update number update_post_meta($id, 'sp_number', sp_array_value($meta, 'sp_number')); // Update positions $positions = explode('|', sp_array_value($meta, 'sp_position')); wp_set_object_terms($id, $positions, 'sp_position', false); // Update leagues $leagues = explode('|', sp_array_value($meta, 'sp_league')); wp_set_object_terms($id, $leagues, 'sp_league', false); // Update seasons $seasons = explode('|', sp_array_value($meta, 'sp_season')); 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) { // 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')); } $team_id = $team_object->ID; } else { $team_id = wp_insert_post(array('post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $team)); // Flag as import update_post_meta($team_id, '_sp_import', 1); wp_set_object_terms($team_id, $leagues, 'sp_league', false); wp_set_object_terms($team_id, $seasons, 'sp_season', false); } // Add team to player add_post_meta($id, 'sp_team', $team_id); // Update current team if first in array if ($i == 0) { update_post_meta($id, 'sp_current_team', $team_id); } $i++; } // Update nationality $nationality = trim(strtolower(sp_array_value($meta, 'sp_nationality'))); if ($nationality == '*') { $nationality = ''; } update_post_meta($id, 'sp_nationality', $nationality); $this->imported++; } // Show Result echo '<div class="updated settings-error below-h2"><p> ' . sprintf(__('Import complete - imported <strong>%s</strong> players and skipped <strong>%s</strong>.', 'sportspress'), $this->imported, $this->skipped) . ' </p></div>'; $this->import_end(); }
/** * Sort the table by priorities. * * @param array $a * @param array $b * @return int */ public function sort($a, $b) { // Loop through priorities if (is_array($this->priorities)) { foreach ($this->priorities as $priority) { // Proceed if columns are not equal if (sp_array_value($a, $priority['key'], 0) != sp_array_value($b, $priority['key'], 0)) { if ($priority['key'] == 'name') { $output = strcmp(sp_array_value($a, 'name', null), sp_array_value($b, 'name', null)); } else { // Compare performance values $output = sp_array_value($a, $priority['key'], 0) - sp_array_value($b, $priority['key'], 0); } // Flip value if descending order if ($priority['order'] == 'DESC') { $output = 0 - $output; } return $output > 0; } } } // Default sort by number return sp_array_value($a, 'number', 0) - sp_array_value($b, 'number', 0); }