|
19 | 19 | </style>
|
20 | 20 |
|
21 | 21 | <?php
|
22 |
| - |
23 | 22 | $action = $_GET['action'];
|
24 |
| -$q = $_GET['q']; |
25 |
| -$p = intval($_GET['p']); |
26 |
| -if ($p <1) $p = 1; |
| 23 | +$q = isset($_GET['q'])? $_GET['q']:""; |
| 24 | +$p = isset($_GET['p'])?intval($_GET['p']):1; |
27 | 25 |
|
28 | 26 | echo "<center><div id='list' style='width:400px;text-align:left'>";
|
29 | 27 |
|
|
119 | 117 | if ($json) {
|
120 | 118 | echo "<h1>search packages</h1>";
|
121 | 119 | foreach ($json['results'] as $result) {
|
122 |
| - echo "<label><input type='checkbox' name='".$result['name']."' value='".$result['name']."'/>" . $result['name'] . "</label><br/>"; |
| 120 | + echo "<label><input type='checkbox' name='".$result['name']."' value='".$result['name']."'/>" . $result['name'] . "</label><span class='span'><a id='merge' href='admin.php?q=" . $q . "&page=" . $p."&name=".$result['name']."&repository=".base64_encode($result['repository'])."'>add</a></span> |
| 121 | +<br/>"; |
123 | 122 | }
|
124 | 123 | if ($next) {
|
125 | 124 | echo "<a href='/admin.php?q=".$q."&p=".$p."'>next</a>";
|
126 | 125 | }
|
127 | 126 |
|
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 |
| -// } |
| 127 | + $repository = isset($_GET['repository']) ? $_GET['repository']:''; |
| 128 | + $name = isset($_GET['name']) ? $_GET['name']:''; |
| 129 | + if(!empty($repository) && !empty($name)){ |
| 130 | + repository($name,$repository); |
| 131 | + } |
148 | 132 |
|
149 | 133 |
|
150 | 134 | echo "<pre>";
|
@@ -197,3 +181,38 @@ function curl_text($url) {
|
197 | 181 | return $result;
|
198 | 182 | }
|
199 | 183 |
|
| 184 | +function repository($name,$repository){ |
| 185 | + $fileGet = file_get_contents(__DIR__ . "/../satis.json"); |
| 186 | + |
| 187 | + $fileData = json_decode($fileGet,true); |
| 188 | + $requireName = array($name => '*'); |
| 189 | + |
| 190 | + |
| 191 | + $merge = array_merge($fileData['require'], $requireName); |
| 192 | + |
| 193 | + $fileData['require'] = $merge; |
| 194 | + |
| 195 | + $repositoriesData[] = array( |
| 196 | + 'type' => 'git', |
| 197 | + 'url' => base64_decode($repository) |
| 198 | + ); |
| 199 | + $url=array(); |
| 200 | + foreach($fileData['repositories'] as $k=>$v) { |
| 201 | + $url[] = $v['url']; |
| 202 | + } |
| 203 | + |
| 204 | + if (!in_array(base64_decode($repository), $url)) { |
| 205 | + |
| 206 | + $newData = array_merge($fileData['repositories'], $repositoriesData); |
| 207 | + $fileData['repositories'] = $newData; |
| 208 | + } |
| 209 | + echo '<pre>'; |
| 210 | + print_r($fileData['repositories']); |
| 211 | + echo '</pre>'; |
| 212 | + file_put_contents(__DIR__ . "/../satis.json",json_encode($fileData)); |
| 213 | + |
| 214 | + |
| 215 | +} |
| 216 | + |
| 217 | + |
| 218 | + |
0 commit comments