/** * The shortcodes controller * * @param mixed $attributes * @return void */ public function shortcodes_controller($attributes) { // Extract data extract(shortcode_atts(array('id' => 1, 'type' => 'table', 'style' => 'general', 'id_team' => '', 'latest' => 'false'), $attributes)); // TODO - In the future, make a specific Front_Controller for every sport. // Make sure the ID is an integer $id = (int) $id; // Get front-end methods $front = new PHPLeague_Front(); // Display ranking table if ($type == 'table') { if ($style == 'home') { return $front->get_league_table($id, 'home', $latest); } elseif ($style == 'away') { return $front->get_league_table($id, 'away', $latest); } else { return $front->get_league_table($id, 'general', $latest); } } elseif ($type == 'fixture') { return $front->get_league_fixture($id); } elseif ($type == 'fixtures') { if (!empty($id_team)) { return $front->get_league_fixtures($id, $id_team); } else { return $front->get_league_fixtures($id); } } elseif ($type == 'club') { return $front->get_club_information($id); } elseif ($type == 'clubs') { return $front->get_clubs_information(); } else { return $front->get_league_table($id); } }
/** * Show the league ranking table. * * @param integer $id_league * @param string $style * @param string $last_results * @return string */ public function get_league_table($id_league, $style = 'general', $last_results = 'true') { global $wpdb; $db = new PHPLeague_Database(); // League not found in the database if ($db->is_league_exists($id_league) === FALSE) { return; } $setting = $db->get_league_settings($id_league); $sport = (string) $setting->sport; $nb_teams = (int) $setting->nb_teams; $promotion = (int) $setting->promotion; $qualifying = (int) $setting->qualifying + $promotion; $favorite = (int) $setting->id_favorite; $relegation = $nb_teams - (int) $setting->relegation; $team_links = $setting->team_link == 'yes' ? TRUE : FALSE; if ($sport != null && in_array($sport, array_keys(PHPLeague_Sports::$sports))) { $sport_inst = new PHPLeague_Sports::$sports[$sport](); return $sport_inst->results_table($id_league); } // We display club information if (isset($_GET['club'])) { $front = new PHPLeague_Front(); echo $front->get_club_information((int) $_GET['club']); } if ($last_results == 'true') { $th_latest = '<th>' . __('Last 5 matches', 'phpleague') . '</th>'; } else { $th_latest = ''; } $output = '<table id="phpleague"><thead><tr>' . '<th class="centered">' . __('Pos', 'phpleague') . '</th>' . '<th>' . __('Team', 'phpleague') . '</th>' . '<th class="centered">' . __('Pts', 'phpleague') . '</th>' . '<th class="centered">' . __('P', 'phpleague') . '</th>' . '<th class="centered">' . __('W', 'phpleague') . '</th>' . '<th class="centered">' . __('D', 'phpleague') . '</th>' . '<th class="centered">' . __('L', 'phpleague') . '</th>' . '<th class="centered">' . __('F', 'phpleague') . '</th>' . '<th class="centered">' . __('A', 'phpleague') . '</th>' . '<th class="centered">' . __('+/-', 'phpleague') . '</th>' . $th_latest . '<th class="centered"></th></tr></thead><tbody>'; $place = 1; foreach ($db->get_league_table_data($style, $id_league, $nb_teams) as $row) { // User want to show team links? if ($team_links) { $permalink = get_permalink(); $url = add_query_arg('club', $row->id_club, $permalink); } if ($place <= $nb_teams) { if ($favorite == $row->id_team) { $output .= '<tr class="id-favorite">'; } else { $output .= '<tr>'; } if ($place <= $promotion) { $span = '<span class="promotion"></span>'; } elseif ($place <= $qualifying) { $span = '<span class="qualifying"></span>'; } elseif ($place > $relegation) { $span = '<span class="relegation"></span>'; } else { $span = '<span></span>'; } if ($style == 'home') { $points = (int) $row->home_points; $played = (int) $row->home_played; $victory = (int) $row->home_v; $draw = (int) $row->home_d; $defeat = (int) $row->home_l; $goal_for = (int) $row->home_g_for; $goal_against = (int) $row->home_g_against; $diff = (int) $row->home_diff; } elseif ($style == 'away') { $points = (int) $row->away_points; $played = (int) $row->away_played; $victory = (int) $row->away_v; $draw = (int) $row->away_d; $defeat = (int) $row->away_l; $goal_for = (int) $row->away_g_for; $goal_against = (int) $row->away_g_against; $diff = (int) $row->away_diff; } else { $points = (int) $row->points; $played = (int) $row->played; $victory = (int) $row->victory; $draw = (int) $row->draw; $defeat = (int) $row->defeat; $goal_for = (int) $row->goal_for; $goal_against = (int) $row->goal_against; $diff = (int) $row->diff; } $output .= '<td class="centered">' . $place . '</td>'; // If a logo has been found, we display it! if (is_file(WP_PHPLEAGUE_UPLOADS_PATH . 'logo_mini/' . $row->logo_mini)) { if (empty($url)) { $output .= '<td><img src="' . content_url('uploads/phpleague/logo_mini/' . $row->logo_mini) . '" alt="' . esc_html($row->club_name) . '" /> ' . esc_html($row->club_name) . '</td>'; } else { $output .= '<td><img src="' . content_url('uploads/phpleague/logo_mini/' . $row->logo_mini) . '" alt="' . esc_html($row->club_name) . '" /> <a title="' . esc_html($row->club_name) . '" href="' . $url . '">' . esc_html($row->club_name) . '</a></td>'; } } else { if (empty($url)) { $output .= '<td>' . esc_html($row->club_name) . '</td>'; } else { $output .= '<td><a title="' . esc_html($row->club_name) . '" href="' . $url . '">' . esc_html($row->club_name) . '</a></td>'; } } $output .= '<td class="centered">' . $points . '</td>'; $output .= '<td class="centered">' . $played . '</td>'; $output .= '<td class="centered">' . $victory . '</td>'; $output .= '<td class="centered">' . $draw . '</td>'; $output .= '<td class="centered">' . $defeat . '</td>'; $output .= '<td class="centered">' . $goal_for . '</td>'; $output .= '<td class="centered">' . $goal_against . '</td>'; $output .= '<td class="centered">' . $diff . '</td>'; // Show latest results if enabled if ($last_results == 'true') { // Open the td tag $output .= '<td>'; // Get the latest results $results = array_reverse($db->get_latest_results($row->id_team)); foreach ($results as $result) { if ($row->id_team == $result->id_team_home) { if ($result->goal_home > $result->goal_away) { $output .= '<span class="win">' . __('W', 'phpleague') . '</span>'; } elseif ($result->goal_home < $result->goal_away) { $output .= '<span class="lose">' . __('L', 'phpleague') . '</span>'; } elseif ($result->goal_home == $result->goal_away) { $output .= '<span class="draw">' . __('D', 'phpleague') . '</span>'; } } elseif ($row->id_team == $result->id_team_away) { if ($result->goal_home < $result->goal_away) { $output .= '<span class="win">' . __('W', 'phpleague') . '</span>'; } elseif ($result->goal_home > $result->goal_away) { $output .= '<span class="lose">' . __('L', 'phpleague') . '</span>'; } elseif ($result->goal_home == $result->goal_away) { $output .= '<span class="draw">' . __('D', 'phpleague') . '</span>'; } } } // Close the td tag $output .= '</td>'; } $output .= '<td class="centered">' . $span . '</td></tr>'; $place++; } } $output .= '</tbody></table>'; return $output; }