Browse Source

Adding latest commits description when update is available

thanks to Adjo for the code. Will need full localization later if accepted.
®omano 8 năm trước cách đây
mục cha
commit
8b4470a093
1 tập tin đã thay đổi với 31 bổ sung1 xóa
  1. 31 1
      modules/update/update.php

+ 31 - 1
modules/update/update.php

@@ -146,6 +146,36 @@ function exec_ogp_module()
 			else
 				echo "<form action='?m=".$_GET['m']."&amp;p=updating&amp;version=".$seed."' method='post'>\n".
 					 "<input type='submit' value='".get_lang('update_now')."' /></form><br><br>\n";
+							
+				echo "<h2>Latest Changes</h2>";
+				
+				$commitsStart = 0;
+				$commitsToShow = 5;
+				
+				$gitHubUpdateName = (!empty($settings['custom_github_update_username']) ? $settings['custom_github_update_username'] : 'OpenGamePanel');
+				$ch = curl_init();
+				curl_setopt($ch, CURLOPT_URL, 'https://api.github.com/repos/'.$gitHubUpdateName.'/'.REPONAME.'/commits');
+				curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0');
+				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+				$data = curl_exec($ch);
+				
+				if ($data) {
+					$json = json_decode($data, true);
+					
+					if (!empty($json[0]['commit'])) {
+						echo '<ul>';
+						foreach ($json as $k=>$v) {
+							echo '<li>'.substr($v['commit']['author']['date'],0,10).' - '.$v['commit']['author']['name'] .'</a> committed <a href="'.$v['html_url'].'" target="_blank">'.substr($v[sha],0,7).'...</a><br>';
+							echo '<b>'.$v['commit']['message'] .'</b></li><br>';
+							if ($commitsStart >= $commitsToShow) {
+								break;
+							}
+							++$commitsStart;
+						}
+						echo '</ul>';
+					}
+				}
 		}
 		else
 		{
@@ -153,4 +183,4 @@ function exec_ogp_module()
 		}
 	}
 }
-?>
+?>