Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.36 KB | None | 0 0
  1. <?php
  2. global $match_id;
  3. global $wpdb;
  4. $match_id = get_query_var( 'id' );
  5. if(!$match_id) { echo 'No Match Selected <a href="#" onclick="javascript:history.back()">Go Back</a>'; goto skip; }
  6.  
  7. $curl = curl_init();
  8.  
  9. curl_setopt_array($curl, [
  10.     CURLOPT_URL => "https://.com/match.json?match=$match_id",
  11.     CURLOPT_RETURNTRANSFER => true,
  12.     CURLOPT_FOLLOWLOCATION => true,
  13.     CURLOPT_ENCODING => "",
  14.     CURLOPT_MAXREDIRS => 10,
  15.     CURLOPT_TIMEOUT => 30,
  16.     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  17.     CURLOPT_CUSTOMREQUEST => "GET",
  18.     CURLOPT_HTTPHEADER => [
  19.         "x-rapidapi-host: ",
  20.         "x-rapidapi-key: "
  21.     ],
  22. ]);
  23.  
  24. $response = curl_exec($curl);
  25. $err = curl_error($curl);
  26.  
  27. curl_close($curl);
  28.  
  29. if ($err) {
  30.     echo "cURL Error #:" . $err;
  31. } else {
  32.     $json_decoded = $response;
  33.     $json_decoded = json_decode($json_decoded, true);
  34. }
  35.  
  36. function display_match_comments() {
  37.     global $current_user; wp_get_current_user();
  38.     global $match_id;
  39.     global $wpdb;
  40.     echo '<div class="latest_results" style="background:#ffffff; text-align:left !important;"">';
  41.     echo '<h6 style="text-align:center !important;">User Comments and Pictures';
  42.     if ( is_user_logged_in() ) {
  43.         echo ' <a href="#add_comment">Add Comment</a>';
  44.     }
  45.     echo '</h6>';
  46.     $content_size = 'one_half';
  47.     $table_name = 'wp_match_comments';
  48.     $row2 = $wpdb->get_results( "SELECT * FROM $table_name WHERE gameid = $match_id");
  49.     if(!$row2) { echo 'No Comments Found</span>'; }
  50.     foreach($row2 as $row2) {
  51.             if(!$content_size){ $content_size = "one_half"; }
  52.             echo '<div class="'.$content_size.'">';
  53.             echo '<div class="latest_results" style="background:#ffffff;">';
  54.             echo '<h6><a href="https://www.husupporters.club/forums/users/'.$row2->name.'">'.$row2->name.'</a></h6>';
  55.             echo '<span>'.$row2->content.'</span><br>';
  56.             $text_to_be_wrapped_in_shortcode = '<span><a href="https://www.husupporters.club/wp-admin/admin.php?page=match_comments&id='.$row2->id.'">Manage Comment</a></span>';
  57.             echo do_shortcode( '[UAS_role roles="administrator, moderator"]' . $text_to_be_wrapped_in_shortcode . '[/UAS_role]' );
  58.             echo '</div>';
  59.             echo '</div>';
  60.             if ($content_size == "one_half") { $content_size = "one_half last_column"; goto skip2; }else{ $content_size = "one_half"; goto skip2; }
  61.             skip2:
  62.         }
  63.     echo '<div id="add_comment" class="latest_results" style="background:#ffffff; text-align:left !important;"">';
  64.     if ( is_user_logged_in() ) {
  65.         echo '<h6 style="text-align:center !important;">Add your own comment and pictures below</h6>';
  66. ?>
  67.     <form method="POST"  action="#">
  68.     <?php wp_editor($content,"content", array('textarea_rows'=>12, 'editor_class'=>'content_class')); ?>
  69.     <input type="hidden" name="name" value="<?php echo $current_user->user_login; ?>"/>
  70.     <input type="hidden" name="gameid" value="<?php echo $match_id; ?>"/>
  71.     <input type="submit" name="submitComment" value="submit" />
  72.     </form>
  73. <?php
  74.     $default = array(
  75.             'name' => '',
  76.             'content' => '',
  77.             'moderation' => '0',
  78.             'gameid' => '',
  79.         );
  80.     $item = shortcode_atts( $default, $_REQUEST );
  81.     if($_POST['submitComment']) {
  82.        $wpdb->prepare($wpdb->insert( $table_name, $item ));
  83.        $comment_success = '1';
  84.        global $comment_success;
  85.     }
  86.     if($comment_success == 1) { echo '<br></span>Comment has been successfully added, once approved it will appear here</span>'; }
  87.  
  88. }else{
  89.     echo '<h6 style="text-align:center !important;"> you must be <a href="https://www.husupporters.club/login-register/">logged in</a>
  90.    to comment</h6>';
  91. }
  92.     echo '</div>';
  93.     echo '</div>';
  94. }
  95.  
  96. foreach ( $json_decoded as $match ){
  97.     display_match($match);
  98. }
  99.  
  100. function display_home_player($home_player, $match){
  101.     $home_player_id = $home_player['player']['id'];
  102.     $matchid = $match['id'];
  103.     if($home_player['sort'] == 12) { echo '<hr>'; }
  104.     echo '<span style="text-align:left !important;">'.$home_player['shirt'].' - '.$home_player['player']['first-name'].' '.$home_player['player']['last-name'].' ';
  105.     if ($home_player['cautioned']['minute']) {
  106.         echo '<span class="fwp-card yellow-card" style="color:#000000;">'.$home_player['cautioned']['minute'].'\' </span>';
  107.     }
  108.     if ($home_player['sent-off']['minute']) {
  109.         echo '<span class="fwp-card red-card" style="color:#ffffff;">'.$home_player['sent-off']['minute'].'\' </span>';
  110.     }
  111.     foreach ( $match['home-team']['goals'] as $home_goals ){
  112.         display_home_goals($home_goals, $home_player_id, $matchid);
  113.     }
  114.     foreach ( $match['home-team']['line-up'] as $home_player_sub ){
  115.         display_home_sub($home_player_sub, $home_player_id, $matchid);
  116.     }
  117.     if ($home_player['substitution']['minute']) { echo '<span style="color:#52FF33; font-size:25px;"> &#8593; </span><span> '.$home_player['substitution']['minute'].'\' </span>'; }
  118.     echo '</span><br>';
  119. }
  120.  
  121. function display_away_player($away_player, $match){
  122.     $away_player_id = $away_player['player']['id'];
  123.     if($away_player['sort'] == 12) { echo '<hr>'; }
  124.     echo '<span style="text-align:left !important;">'.$away_player['shirt'].' - '.$away_player['player']['first-name'].' '.$away_player['player']['last-name'].' ';
  125.     if ($away_player['cautioned']['minute']) {
  126.         echo '<span class="fwp-card yellow-card" style="color:#000000;">'.$away_player['cautioned']['minute'].'\' </span>';
  127.     }
  128.     if ($away_player['sent-off']['minute']) {
  129.         echo '<span class="fwp-card red-card" style="color:#ffffff;">'.$away_player['sent-off']['minute'].'\' </span>';
  130.     }
  131.     foreach ( $match['away-team']['goals'] as $away_goals ){
  132.         display_away_goals($away_goals, $away_player_id);
  133.     }
  134.     foreach ( $match['away-team']['line-up'] as $away_player_sub ){
  135.         display_away_sub($away_player_sub, $away_player_id);
  136.     }
  137.     if ($away_player['substitution']['minute']) { echo '<span style="color:#52FF33; font-size:25px;"> &#8593; </span><span> '.$away_player['substitution']['minute'].'\' </span>'; }
  138.     echo '</span><br>';
  139. }
  140.  
  141. function display_home_goals($home_goals, $home_player_id, $matchid){
  142.     if($matchid == 364310) { goto ebbsfleet_skip2; }
  143. if ($home_goals['player']['id'] == $home_player_id) {
  144.         echo '<span>&#9917; '.$home_goals['minute'].'\' </span> ';
  145.     }
  146. ebbsfleet_skip2:
  147. }
  148.  
  149. function display_home_sub($home_player_sub, $home_player_id, $matchid){
  150.     if($matchid == 364310) { goto ebbsfleet_skip; }
  151.         if ($home_player_sub['substitution']['replaced']['player']['id'] == $home_player_id) {
  152.         echo '<span style="color:#FF0000; font-size:25px;"> &#8595; </span><span> '.$home_player_sub['substitution']['minute'].'\'</span> ';
  153.     }
  154.        ebbsfleet_skip:
  155. }
  156.  
  157. function display_away_goals($away_goals, $away_player_id){
  158.     if ($away_goals['player']['id'] == $away_player_id) {
  159.         echo '<span>&#9917; '.$away_goals['minute'].'\' </span>';
  160.     }
  161. }
  162.  
  163. function display_away_sub($away_player_sub, $away_player_id){
  164.     if ($away_player_sub['substitution']['replaced']['player']['id'] == $away_player_id) {
  165.         echo '<span style="color:#FF0000; font-size:25px;"> &#8595; </span><span> '.$away_player_sub['substitution']['minute'].'\' </span>';
  166.     }
  167. }
  168. function display_match_report($gameid) {
  169.     global $wpdb;
  170.     $row2 = $wpdb->get_results("SELECT * FROM wp_hufc_match_report WHERE gameid = $gameid ");
  171.     foreach ($row2 as $row2) {
  172.         if($row2->author) { echo '<a href="'.$row2->matchlink.'" class="gamedetail" target="_blank">Match Report by '.$row2->author.'</a><br>'; }else{ echo '<a href="'.$row2->matchlink.'" class="gamedetail" target="_blank">Match Report</a><br>'; }
  173.     }
  174.     if(!$row2) {
  175.         $text_to_be_wrapped_in_shortcode = '<span><a href="https://www.husupporters.club/wp-admin/admin.php?page=hufc_match_report&addid='.$gameid.'">Click here</a> to add a report link</span><br>';
  176.         echo do_shortcode( '[UAS_role roles="administrator, moderator"]' . $text_to_be_wrapped_in_shortcode . '[/UAS_role]' );
  177.         echo do_shortcode( '[UAS_specific ids="48, 3"]' . $text_to_be_wrapped_in_shortcode . '[/UAS_specific]' );
  178.    }else {
  179.         $text_to_be_wrapped_in_shortcode = '<span><a href="https://www.husupporters.club/wp-admin/admin.php?page=hufc_match_report&id='.$gameid.'">Click here</a> to edit a report link</span><br>';
  180.         echo do_shortcode( '[UAS_role roles="administrator, moderator"]' . $text_to_be_wrapped_in_shortcode . '[/UAS_role]' );
  181.         echo do_shortcode( '[UAS_specific ids="48, 3"]' . $text_to_be_wrapped_in_shortcode . '[/UAS_specific]' );
  182.    }
  183. }
  184.  
  185.  
  186. function display_match($match){
  187.     global $wpdb;
  188.     global $match_id;
  189.     $home_team_name = strtolower($match['home-team']['name']);
  190.     $home_team_name = preg_replace('/\s+/', '_',$home_team_name);
  191.     $away_team_name = strtolower($match['away-team']['name']);
  192.     $away_team_name = preg_replace('/\s+/', '_',$away_team_name);
  193.     $match_date = date("M jS, Y", strtotime($match['date']));
  194.     echo '<a href="#" onclick="javascript:history.back()" style="float:left !important;">Go Back</a><br>';
  195. echo '<div class="one_half">';
  196.     echo '<div class="latest_results" style="background:#ffffff;">';
  197.     echo '<h6>Final Result</h6>';
  198.     echo '<div class="latest_results_col"><img src="https://www.husupporters.club/wp-content/uploads/team_logos/'.$home_team_name.'.png"><span><a href="https://www.husupporters.club/team-info/'.$match['home-team']['id'].'">'.$match['home-team']['name'].'</a></span>';
  199.     $text_to_be_wrapped_in_shortcode = '<br><span>team ID: '.$match['home-team']['id'].'</span>';
  200.     echo do_shortcode( '[UAS_role roles="administrator"]' . $text_to_be_wrapped_in_shortcode . '[/UAS_role]' );
  201.     echo '</div>';
  202.     echo '<div class="latest_results_col goalscore">'.$match['home-team']['score'].'</div>';
  203.     echo '<div class="latest_results_col goalscore">'.$match['away-team']['score'].'</div>';
  204.     echo '<div class="latest_results_col"><img src="https://www.husupporters.club/wp-content/uploads/team_logos/'.$away_team_name.'.png"><span><a href="https://www.husupporters.club/team-info/'.$match['away-team']['id'].'">'.$match['away-team']['name'].'</a></span>';
  205.         $text_to_be_wrapped_in_shortcode = '<br><span>team ID: '.$match['away-team']['id'].'</span>';
  206.        echo do_shortcode( '[UAS_role roles="administrator"]' . $text_to_be_wrapped_in_shortcode . '[/UAS_role]' );
  207.        echo '</div>';
  208.     echo '<div class="clear">';
  209.     if ($match['home-team']['penalties-score']) {
  210.         $p_home = $match['home-team']['penalties-score'];
  211.         $p_away = $match['away-team']['penalties-score'];
  212.         if ($p_home > $p_away) {
  213.             echo '<span><a href="https://www.husupporters.club/team-info/'.$match['home-team']['id'].'">'.$match['home-team']['name'].'</a> wins '.$match['home-team']['penalties-score'].' - '.$match['away-team']['penalties-score'].' on penalties.</span>';
  214.         }
  215.         if ($p_away > $p_home) {
  216.             echo '<span><a href="https://www.husupporters.club/team-info/'.$match['away-team']['id'].'">'.$match['away-team']['name'].'</a> wins '.$match['away-team']['penalties-score'].' - '.$match['home-team']['penalties-score'].' on penalties.</span>';
  217.         }
  218.     }
  219.     echo '</div>';
  220.     echo '</div>';
  221.     echo '</div>';
  222.     echo '<div class="one_half last_column">';
  223.     echo '<div class="latest_results" style="background:#ffffff">';
  224.     echo '<h6>Match Information</h6><br>';
  225.     echo '<span>Date: '.$match_date.'</span><br>';
  226.     echo '<span>Competition: '.$match['competition']['name'].'</span><br>';
  227.     echo '<span>Kick Off: '.$match['time'].'</span><br>';
  228.     echo '<span>Venue: '.$match['venue'].'</span><br>';
  229.     echo '<span>Half Time: <a href="https://www.husupporters.club/team-info/'.$match['home-team']['id'].'">'.$match['home-team']['name'].'</a> '.$match['home-team']['half-time-score'].' - '.$match['away-team']['half-time-score'].' <a href="https://www.husupporters.club/team-info/'.$match['away-team']['id'].'">'.$match['away-team']['name'].'</a></span><br>';
  230.     echo '<span>Attendance: '.$match['attendance'].'</span><br>';
  231.     $gameid = $match['id'];
  232.     display_match_report($gameid);
  233.     $text_to_be_wrapped_in_shortcode = '<span>Match ID: '.$match['id'].'</span>';
  234.     echo do_shortcode( '[UAS_role roles="administrator, moderator"]' . $text_to_be_wrapped_in_shortcode . '[/UAS_role]' );
  235.     echo '</div></div>';
  236.     echo '<div class="one_half">';
  237.     echo '<div class="latest_results" style="background:#ffffff; text-align:left !important;" >';
  238.     echo '<h6 style="text-align:center !important;"><a href="https://www.husupporters.club/team-info/'.$match['home-team']['id'].'">'.$match['home-team']['name'].'</a></h6>';
  239.     if($match['id'] == 364310) { echo '<span>We are aware of an issue with goal and substitution data of this game, this is due to the data not being recorded correctly<br> Goal scorers for Ebbsfleet were: Lee Martin (59\' pen) & Ben Chapman (90\')<br>Substitutions are as follows: Jack Paxman Replaced Michael West 45\', Rakish Bingham Replaced Reece Grant 45\', Charlie Rowan Replaced James Dobson 87\'</span><br>'; }
  240.         foreach ( $match['home-team']['line-up'] as $home_player ){
  241.         display_home_player($home_player, $match);
  242.     }
  243.     echo '</div></div>';
  244.     echo '<div class="one_half last_column">';
  245.     echo '<div class="latest_results" style="background:#ffffff; text-align:left !important;"">';
  246.     echo '<h6 style="text-align:center !important;"><a href="https://www.husupporters.club/team-info/'.$match['away-team']['id'].'">'.$match['away-team']['name'].'</a></h6>';
  247.     foreach ( $match['away-team']['line-up'] as $away_player ){
  248.         display_away_player($away_player, $match);
  249.     }
  250.     echo '</div></div>';
  251.     display_match_comments();
  252. }
  253. skip:
  254.  
  255. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement