|
4 | 4 | $collapse_class = 'collapse';
|
5 | 5 | $searchTB_text = '';
|
6 | 6 | $size_text = '';
|
| 7 | +$stars_text = ''; |
7 | 8 | $language_text = '';
|
8 |
| -$createdAt_text = ''; |
9 |
| -$pushedAt_text = ''; |
| 9 | +$created_text = ''; |
| 10 | +$pushed_text = ''; |
10 | 11 | if(isset($_POST['searchButton'])){
|
11 | 12 | $collapse_class = 'collapse';
|
12 |
| - $searchTB_text = $_POST['searchTB']; |
13 |
| - $createdAt_text = $_POST['createdAtTB']; |
14 |
| - $pushedAt_text = $_POST['pushedAtTB']; |
15 | 13 | }
|
16 |
| - |
17 |
| - |
18 | 14 | if(isset($_POST['advancedSearchButton'])){
|
19 | 15 | $collapse_class = '';
|
20 |
| - $searchTB_text = $_POST['searchTB']; |
| 16 | +} |
| 17 | + |
| 18 | +if(isset($_POST['searchButton']) || isset($_POST['advancedSearchButton'])){ |
| 19 | + $searchTB_text = $_POST['searchTB']; |
21 | 20 | $size_text = $_POST['size'];
|
| 21 | + $stars_text = $_POST['stars']; |
22 | 22 | $language_text = $_POST['language'];
|
23 |
| - $createdAt_text = $_POST['createdAtTB']; |
24 |
| - $pushedAt_text = $_POST['pushedAtTB']; |
25 |
| - |
| 23 | + $created_text = $_POST['created']; |
| 24 | + $pushed_text = $_POST['pushed']; |
26 | 25 | }
|
27 | 26 |
|
28 |
| - |
| 27 | +print GITHUB_INSTRUCTION; |
29 | 28 | print '<form name ="searchForm" method="post">';
|
30 | 29 |
|
31 | 30 | print '<div class="alert alert-secondary">
|
32 | 31 | Repository Search
|
33 | 32 | <div class="input-group mb-3">
|
34 | 33 | <input name="searchTB" type="text" class="form-control" aria-label="Text input with segmented dropdown button" placeholder="keywords for search" value ="'.$searchTB_text.'">
|
| 34 | + <select class="custom-select" name="github_account" required> |
| 35 | + <option selected value="0">Choose GITHUB account</option>'; |
| 36 | + foreach (GITHUB_CREDENTIALS as $key => $credential) { |
| 37 | + if(isset($_POST['github_account']) && $_POST['github_account'] == $key){$select_str = 'selected';}else{$select_str = '';} |
| 38 | + print '<option value="'.$key.'" '.$select_str.'>USERNAME: '.$credential['username'].', PASSWORD: '.substr($credential['password'], 0, 2).'*****'.substr($credential['password'], -2).'</option>'; |
| 39 | + } |
| 40 | + |
| 41 | + print '</select> |
35 | 42 | <div class="input-group-append">
|
36 | 43 | <button name="searchButton" type="submit" class="btn btn-primary" value="1">Search</button>
|
37 | 44 | <button class="btn btn-success" type="button" data-toggle="collapse" data-target="#collapseAdvancedSearch" aria-expanded="false" aria-controls="collapseAdvancedSearch">Advanced Search</button>
|
|
48 | 55 | <div class="row"><div class="col-sm-4">
|
49 | 56 | '.create_input('Size','text','size',$size_text,'','','Help: matches repositories that are at least 30000 (30 MB).', false).'
|
50 | 57 | </div><div class="col-sm-4">
|
51 |
| -'.create_input('Number of stars','text','stars','','','','Help: matches repositories with the at least 500 stars.', false).' |
| 58 | +'.create_input('Number of stars','text','stars',$stars_text,'','','Help: matches repositories with the at least 500 stars.', false).' |
52 | 59 | </div><div class="col-sm-4">
|
53 | 60 | '.create_input('language','text','language',$language_text,'','','Help: matches repositories with the word "rails" that are written in JavaScript.', false).'
|
54 | 61 | </div></div>
|
55 | 62 |
|
56 | 63 |
|
57 | 64 | <div class="row"><div class="col-sm-4">
|
58 |
| -'.create_input('Created','text','created','','','','Help: matches repositories that were created before 2011.', false).' |
| 65 | +'.create_input('Created','text','created',$created_text,'','','Help: matches repositories that were created before 2011.', false).' |
59 | 66 | </div><div class="col-sm-4">
|
60 |
| -'.create_input('Pushed','text','pushed','','','','Help: matches repositories with the word "css" that were pushed to after January 2013.', false).' |
| 67 | +'.create_input('Pushed','text','pushed',$pushed_text,'','','Help: matches repositories with the word "css" that were pushed to after January 2013.', false).' |
61 | 68 | </div><div class="col-sm-4">
|
62 | 69 |
|
63 | 70 | </div></div>
|
|
133 | 140 | $header_array = array('Accept: application/vnd.github.machine-man-preview+json', 'User-Agent: Awesome-Octocat-App');
|
134 | 141 |
|
135 | 142 | if(!empty($_POST['size'] )){$searchTB_text.=' size:>='.$size_text;}
|
| 143 | + if(!empty($_POST['stars'] )){$searchTB_text.=' stars>:'.$stars_text;} |
136 | 144 | if(!empty($_POST['language'] )){$searchTB_text.=' language:'.$language_text;}
|
| 145 | + if(!empty($_POST['created'] )){$searchTB_text.=' created:>='.$created_text;} |
| 146 | + if(!empty($_POST['pushed'] )){$searchTB_text.=' pushed:>='.$pushed_text;} |
137 | 147 |
|
138 | 148 | $page =1;
|
139 | 149 | $count_repo = 0;
|
| 150 | + $account_no = $_POST['github_account']; |
140 | 151 | while (1) {
|
141 | 152 | $data = array('q'=> $searchTB_text, 'page' => $page, 'per_page'=> 100);
|
142 | 153 | $url = 'https://api.github.com/search/repositories';
|
143 |
| - $result_json = callAPI('GET', $url, $data, $header_array, GITHUB_USERNAME, GITHUB_PASSWORD); |
| 154 | + $result_json = callAPI('GET', $url, $data, $header_array, GITHUB_CREDENTIALS[$account_no]['username'], GITHUB_CREDENTIALS[$account_no]['password']); |
144 | 155 | $result = json_decode($result_json, true);
|
145 |
| - lau($result); |
| 156 | + if(!isset($result['total_count'])){ |
| 157 | + printf('<div class="alert alert-danger">Search operation is stopped. Reason is given below.</div>'); |
| 158 | + lau($result); |
| 159 | + } |
146 | 160 | if(isset($result['items'])){
|
147 | 161 | $data = $result['items'];
|
148 | 162 | }else{
|
149 | 163 | $data = array();
|
150 | 164 | }
|
151 | 165 |
|
152 | 166 | if($page==1){
|
| 167 | + $total_count = $result['total_count']; |
153 | 168 | $table_str= "<table id='mytable' class='table table-striped table-bordered' style='width:100%'><thead><tr>";
|
154 | 169 | $table_str.= '<th>#</th><th>Name</th><th>Owner Name</th><th>Size</th><th>Stars</th><th>Watchers</th><th>Language</th><th>Created Date</th><th>Last Updated</th><th>Last Pushed</th>';
|
155 | 170 | $table_str.= '<th>Action</th></tr></thead><tbody>';
|
|
188 | 203 | if($count_repo >= 1000){
|
189 | 204 | $max_str = '(GITHUB Limitation: Maximum 1000 entries are returned. For more details at <a target="_blank" href ="https://developer.github.com/v3/search/#search-repositories">Click Here</a>).';
|
190 | 205 | }
|
191 |
| - $count_str = '<div class="alert alert-success">Showing <b>'.$count_repo.'</b> of <b>'. $result['total_count'].'</b> repositories. '.$max_str.'</div>'; |
| 206 | + $count_str = '<div class="alert alert-success">Showing <b>'.$count_repo.'</b> of <b>'.$total_count.'</b> repositories. '.$max_str.'</div>'; |
192 | 207 |
|
193 | 208 |
|
194 | 209 | print $count_str.$table_str ;
|
|
199 | 214 | <script type="text/javascript">
|
200 | 215 | $(document).ready(function() {
|
201 | 216 | var t = $(\'#mytable\').DataTable({
|
| 217 | + dom: \'Bfrtip\', |
| 218 | + buttons: [ |
| 219 | + \'copy\', \'excel\', \'pdf\' |
| 220 | + ], |
202 | 221 | "order": [[ 3, "desc" ]]
|
203 | 222 | });
|
204 | 223 |
|
|
0 commit comments