|
1 | 1 | <center>
|
2 |
| -<br/> |
| 2 | + |
3 | 3 | <div style="width:400px;">
|
4 |
| -<form action="/admin.php" method="GET"> |
5 |
| -<input name="q" type="text" style="width:300px;height:35px;line-height:35px;font-size:25px;"/> |
6 |
| -<input type="submit" value="search" style=";height:35px;line-height:35px;font-size:25px;" /> |
| 4 | +<form action="/admin.php?action=query" method="GET"> |
| 5 | + <p style="text-align: left;">搜索</p> |
| 6 | + <input name="q" type="text" style="width:300px;height:35px;line-height:35px;font-size:25px;"/> |
| 7 | + <input type="submit" value="search" style=";height:35px;line-height:35px;font-size:25px;" /> |
| 8 | +</form> |
| 9 | + |
| 10 | +<form action="/admin.php?action=upload" method="post" enctype="multipart/form-data"> |
| 11 | + <p style="text-align: left;">上传composer.lock</p> |
| 12 | + <input name="file" type="file" style="width:300px;height:35px;line-height:35px;font-size:25px;"/> |
| 13 | + <input type="submit" value="upload" style=";height:35px;line-height:35px;font-size:25px;" /> |
7 | 14 | </form>
|
8 | 15 | </div>
|
9 | 16 | </center>
|
|
13 | 20 |
|
14 | 21 | <?php
|
15 | 22 |
|
| 23 | +$action = $_GET['action']; |
16 | 24 | $q = $_GET['q'];
|
17 | 25 | $p = intval($_GET['p']);
|
18 | 26 | if ($p <1) $p = 1;
|
19 | 27 |
|
20 | 28 | echo "<center><div id='list' style='width:400px;text-align:left'>";
|
21 | 29 |
|
| 30 | + |
| 31 | + |
| 32 | +if ($action == 'upload') { |
| 33 | + $tmp_file = isset($_FILES['file']['tmp_name'])?$_FILES['file']['tmp_name']:""; |
| 34 | + |
| 35 | + if ($tmp_file) { |
| 36 | + $json = @json_decode(file_get_contents($tmp_file), true); |
| 37 | + |
| 38 | + $packages = array_merge( |
| 39 | + isset($json['packages'])? $json['packages'] : array(), |
| 40 | + isset($json['packages-dev']) ? $json['packages-dev'] : array() |
| 41 | + ); |
| 42 | + if (empty($packages)) { |
| 43 | + echo "请上传composer.lock文件"; |
| 44 | + } |
| 45 | + $repos = array(); |
| 46 | + foreach ($packages as $package) { |
| 47 | + |
| 48 | + if (isset($package['source'])) { |
| 49 | + $source = $package['source']; |
| 50 | + if (isset($source['url']) && isset($source['type'])) { |
| 51 | + $repo = array(); |
| 52 | + $repo['type'] = $source['type']; |
| 53 | + $repo['url'] = $source['url']; |
| 54 | + $repo['version'] = $package['version']; |
| 55 | + $repos[$package['name']] = $repo; |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + echo "<pre>"; |
| 61 | + |
| 62 | + //print_r($repos); |
| 63 | + //读物去sataics.json |
| 64 | + $satis_json_file = __DIR__."/../satis.json"; |
| 65 | + $satisData = @json_decode(file_get_contents($satis_json_file), true); |
| 66 | + |
| 67 | + |
| 68 | + $requires = array(); |
| 69 | + foreach ($repos as $key => $repo) { |
| 70 | + $versionArr = array($repo['version']); |
| 71 | + |
| 72 | + if (isset($satisData['require'][$key])) { |
| 73 | + $old_versions = explode("|", $satisData['require'][$key]); |
| 74 | + $versionArr = array_merge($versionArr, $old_versions); |
| 75 | + $versionArr = array_unique($versionArr); |
| 76 | + } |
| 77 | + $requires[$key] = implode("|", $versionArr); |
| 78 | + |
| 79 | + //print_r(implode("|", $versionArr)); |
| 80 | + //echo "\n"; |
| 81 | + unset($repos[$key]['version']); |
| 82 | + } |
| 83 | + |
| 84 | + $new_require = array_merge( |
| 85 | + $satisData['require'], |
| 86 | + $requires |
| 87 | + ); |
| 88 | + print_r($new_require); |
| 89 | + |
| 90 | + $new_repos = array_merge( |
| 91 | + array_values($repos), |
| 92 | + $satisData['repositories'] |
| 93 | + ); |
| 94 | + |
| 95 | + $satisData['repositories'] = $new_repos; |
| 96 | + $satisData['require'] = $new_require; |
| 97 | + |
| 98 | + file_put_contents($satis_json_file, json_encode($satisData)); |
| 99 | + |
| 100 | + //print_r(json_encode(array_values($repos))); |
| 101 | + echo "</pre>"; |
| 102 | + |
| 103 | + } |
| 104 | + die; |
| 105 | +} |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
22 | 111 | if ($q) {
|
23 |
| - $url = "https://packagist.org/search.json?q=" . $q . "&page=" . $p; |
| 112 | + $url = "https://packagist.org/search.json?action=query&q=" . $q . "&page=" . $p; |
24 | 113 | $result = curl_text($url);
|
25 | 114 | $json = @json_decode($result,true);
|
26 | 115 |
|
27 | 116 | $next = $json['next'];
|
28 | 117 | $p++;
|
29 | 118 |
|
30 |
| - |
31 | 119 | if ($json) {
|
32 | 120 | echo "<h1>search packages</h1>";
|
33 | 121 | foreach ($json['results'] as $result) {
|
|
37 | 125 | echo "<a href='/admin.php?q=".$q."&p=".$p."'>next</a>";
|
38 | 126 | }
|
39 | 127 |
|
40 |
| - |
| 128 | + // Had to use isset, because current version of json-schema |
| 129 | + // cant handle "require" constraints, |
| 130 | + |
| 131 | +// $packages = array_merge( |
| 132 | +// (isset($data->packages)) ? $data->packages : array(), |
| 133 | +// (isset($data->{'packages-dev'})) ? $data->{'packages-dev'} : array() |
| 134 | +// ); |
| 135 | +// |
| 136 | +// $repos = array(); |
| 137 | +// foreach ($packages as $package) { |
| 138 | +// if (isset($package->source)) { |
| 139 | +// $source = $package->source; |
| 140 | +// if (isset($source->url) && isset($source->type)) { |
| 141 | +// $repo = new Repository(); |
| 142 | +// $repo->setUrl($source->url); |
| 143 | +// $repo->setType($source->type); |
| 144 | +// $repos[] = $repo; |
| 145 | +// } |
| 146 | +// } |
| 147 | +// } |
41 | 148 |
|
42 | 149 |
|
43 | 150 | echo "<pre>";
|
|
0 commit comments