Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/feeds.php
blob: 70320e9f1fbc24c75d8804d3066f517666cf9739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<?php

require_once "init.php";

require_once BASE . "/lib/mysql.php";

$uri_parts = explode('/', $_SERVER['REQUEST_URI']);

if ($uri_parts[0] != '' || $uri_parts[1] != 'feeds')
  throw_http_error(422, 'Unprocessable Entity');

$last = array_pop($uri_parts);
if ($last != '')
  array_push($uri_parts, $last);

array_splice(
  $uri_parts,
  0, 2
);

if (count($uri_parts) == 0) { // index page

  require_once BASE . "/lib/style.php";
  require_once BASE . "/lib/format.php";

  print_header("RSS - Feeds");

  $result = mysql_run_query(
    "SELECT DISTINCT `architectures`.`name` FROM `architectures`" .
    mysql_join_architectures_repositories() .
    " WHERE `repositories`.`is_on_master_mirror`" .
    " ORDER BY `name`"
  );
  $archs = array();
  while ($row = $result -> fetch_assoc())
    $archs[$row['name']] = $row['name'] . '/';

  $print_archs = array_merge(
    array(
      '' => '',
      'All Arches' => 'all/'
    ),
    $archs
  );

  $result = mysql_run_query(
    "SELECT DISTINCT `repositories`.`name` FROM `repositories` WHERE `repositories`.`is_on_master_mirror` ORDER BY `name`"
  );
  $repos = array();
  while ($row = $result -> fetch_assoc())
    $repos[$row['name']] = $row['name'] . '/';

  $print_repos = array_merge(
    array(
      'All Repos' => ''
    ),
    $repos
  );

  $bugtracker_projects = array(
    0 => 'All Projects',
    1 => 'Arch Linux 32'
  );

  $bugtracker_operations = array(
    'Opened' => '',
    'Edited' => 'topic=edit&',
    'Closed' => 'topic=clo&'
  );

  function print_arches_header() {
    global $print_archs;
    foreach ($print_archs as $arch => $dummy) {
      print "                <th>\n";
      print "                  " . $arch . "\n";
      print "                </th>\n";
    };
  }

  function print_feeds($prefix) {
    global $print_archs;
    global $print_repos;
    foreach ($print_repos as $repo => $dummy) {
      print "              <tr>\n";
      print "                <td>\n";
      print "                  <strong>" . $repo . "</strong>\n";
      print "                </td>\n";
      foreach ($print_archs as $arch => $dummy) {
        if ($arch == '')
          continue;
        print "                <td>\n";
        print "                  <a href=\"/feeds/packages/" . $prefix . $print_archs[$arch] . $print_repos[$repo] . "\" class=\"rss\">Feed</a>\n";
        print "                </td>\n";
      }
      print "              </tr>\n";
    }
  }

  function print_feeds_table($prefix) {
    print "          <table class=\"pretty2\">\n";
    print "            <thead>\n";
    print "              <tr>\n";
    print_arches_header();
    print "              </tr>\n";
    print "            </thead>\n";
    print "            <tbody>\n";
    print_feeds($prefix);
    print "            </tbody>\n";
    print "          </table>\n";
  }

  ?>
        <div id="rss-feeds" class="box">
          <h2>
            RSS Feeds
          </h2>
          <p>
            Several RSS feeds are available for consumption from the Arch32 website.
            The majority of these are package-related and allow feeds to be customized for the updates you care about.
          </p>
          <h3>
            News Feed
          </h3>
          <p>
            Grab the
            <a href="https://news.archlinux32.org/rss.php" class="rss" title="Arch Linux news feed">news item feed</a>
            to keep up-to-date with the latest news from the Arch Linux development staff.
          </p>
          <h3>
            Package Feeds
          </h3>
          <p>
            If you are interested in
            <a href="/feeds/packages/" class="rss" title="Arch Linux 32 package updates feed">all package updates</a>,
            then grab this feed.
  <?php

  print_feeds_table('');

  ?>
            <p>
              <s>Recently added packages.</s> (to be implemented)
            </p>
  <?php

  // print_feeds_table('added/');

  ?>
            <p>
              <s>Recently removed packages.</s> (to be implemented)
            </p>
  <?php

  // print_feeds_table('removed/');

  ?>
            <h3>
              Release Feed
            </h3>
            <p>
              Grab the
              <a href="/feeds/releases/" class="rss" title="Arch Linux release feed">ISO release feed</a>
              if you want to help seed the ISO release torrents as they come out.
            </p>
            <h3>
              Development Feeds
            </h3>
            <p>
              Subscribe to any of the following to track bug tickets and feature requests from the
              <a href="https://bugs.archlinux32.org/" title="Arch Linux 32 Bugs">Arch Linux 32 Bugtracker</a>:
            </p>
            <table class="pretty2">
              <thead>
                <tr>
                  <th>
                    Project
                  </th>
  <?php

  foreach ($bugtracker_operations as $label => $dummy) {
    print "                <th>\n";
    print "                  Recently " . $label . " Tasks\n";
    print "                </th>\n";
  }

  ?>
                </tr>
              </thead>
              <tbody>
  <?php

  foreach ($bugtracker_projects as $id => $project) {
    print "              <tr>\n";
    print "                <td>\n";
    print "                  " . $project . "\n";
    print "                </td>\n";
    foreach ($bugtracker_operations as $label => $option) {
      print "                <td>\n";
      print "                  <a href=\"https://bugs.archlinux.org/feed.php?feed_type=rss2&" . $option . "project=" . $id . "\" class=\"rss\">Feed</a>\n";
      print "                </td>\n";
    }
    print "              </tr>\n";
  }

  ?>
              </tbody>
            </table>
          </div>
  <?php

  print_footer();

  die();

} // index page

if ($uri_parts[0] == 'releases') {
  if (count($uri_parts) != 1)
    throw_http_error(501, "Not Implemented", '/feeds/' . implode('/',$uri_parts));
  $available_isos = apcu_fetch('available_isos', $apcu_success);
  if ($apcu_success == false || true) {
    $ch = curl_init("https://mirror.archlinux32.org/archisos/");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $listing = curl_exec($ch);
    curl_close($ch);
    preg_match_all(
      ',<a href="(archlinux-([0-9]{4}\.[0-9]{2}\.[0-9]{2})-([^.]+)\.iso)">\1</a>\s+(\S+)\s+\S+\s+([0-9]+)\s*\n,',
      $listing,
      $matches,
      PREG_SET_ORDER
    );
    $available_isos = array();
    foreach ($matches as $match) {
      $available_isos[] = array(
        'file' => $match[1],
        'title' => $match[2] . '-' . $match[3],
        'build_date' => strtotime(str_replace('.', '-', $match[2])),
        'build_type' => $match[3],
        'release_date' => $match[4],
        'size' => $match[5]
      );
    }
    apcu_store('available_isos', $available_isos, 3600);
  }

  header('Content-Type: application/rss+xml; charset=utf-8');
  print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
  print "<rss version=\"2.0\">";
  print "<channel>";
  print "<title>";
  print "Arch Linux 32: Releases";
  print "</title>";
  print "<link>";
  print "https://www.archlinux32.org/download/";
  print "</link>";
  print "<description>";
  print "Release ISOs";
  print "</description>";
  print "<atom:link href=\"https://www.archlinux32.org/feeds/releases/\" rel=\"self\">";
  print "</atom:link>";
  print "<language>";
  print "en-us";
  print "</language>";
  print "<lastBuildDate>";
  print date('Y-m-d', $available_isos[0]['build_date']);
  print "</lastBuildDate>";
  foreach ($available_isos as $available_iso) {
    print "<item>";
    print "<title>";
    print $available_iso['title'];
    print "</title>";
    // TODO: link to iso description (do we want that?)
    print "<description>";
    print "</description>";
    print "<pubDate>";
    print date('Y-m-d', $available_iso['release_date']);
    print "</pubDate>";
    // TODO: guid
    print "<enclosure length=\"";
    print date('Y-m-d', $available_iso['size']);
    print "\" type=\"application/x-bittorrent\">";
    // TODO: url=\"https://www.archlinux32.org/iso/2019.02.01/archlinux-2019.02.01-x86_64.iso.torrent\">";
    print "</enclosure>";
    print "</item>";
  }
  print "</channel>";
  print "</rss>";

  die();
} // releases

if ($uri_parts[0] == 'packages') {

  array_splice(
    $uri_parts,
    0, 1
  );

// TODO: implement "added" and "removed" - but how?
//  $actions = array('' => '', 'added' => 'added', 'removed' => 'removed');
  $actions = array('' => '');
  $archs = array('all' => 'all');
  $result = mysql_run_query(
    "SELECT DISTINCT `architectures`.`name` FROM `architectures`" .
    mysql_join_architectures_repositories() .
    " WHERE `repositories`.`is_on_master_mirror`" .
    " ORDER BY `name`"
  );
  while ($row = $result -> fetch_assoc())
    $archs[$row['name']] = $row['name'];
  $repos = array('' => '');
  $result = mysql_run_query(
    "SELECT DISTINCT `repositories`.`name` FROM `repositories` WHERE `repositories`.`is_on_master_mirror` ORDER BY `name`"
  );
  while ($row = $result -> fetch_assoc())
    $repos[$row['name']] = $row['name'];

  if (count($uri_parts) > 0 && array_key_exists($uri_parts[0], $actions)) {
    $action = $uri_parts[0];
    $action_filter = 'unimplemented';
    array_splice(
      $uri_parts,
      0, 1
    );
  }
  else {
    $action = '';
    $action_filter = '`repositories`.`is_on_master_mirror`';
  }

  if (count($uri_parts) > 0) {
    if (!array_key_exists($uri_parts[0], $archs))
      throw_http_error(501, "Not Implemented", implode('/',$uri_parts));
    $arch = $uri_parts[0];
    $arch_filter = ' AND `r_a`.`name`="' . $arch . '"';
    array_splice(
      $uri_parts,
      0, 1
    );
  }
  else {
    $arch = '';
    $arch_filter = '';
  }

  if (count($uri_parts) > 0) {
    if (!array_key_exists($uri_parts[0], $repos))
      throw_http_error(501, "Not Implemented", implode('/',$uri_parts));
    $repo = $uri_parts[0];
    $repo_filter = ' AND `repositories`.`name`="' . $repo . '"';
    array_splice(
      $uri_parts,
      0, 1
    );
  }
  else {
    $repo = '';
    $repo_filter = '';
  }

  if (count($uri_parts) != 0)
    throw_http_error(501, "Not Implemented", implode('/',$uri_parts));

  $result = mysql_run_query(
    "SELECT MAX(`build_assignments`.`return_date`) AS `max_build_date`" .
    " FROM `build_assignments`" .
    mysql_join_build_assignments_binary_packages() .
    mysql_join_binary_packages_binary_packages_in_repositories() .
    mysql_join_binary_packages_in_repositories_repositories() .
    mysql_join_repositories_architectures("", "r_a") .
    " WHERE " . $action_filter . $repo_filter . $arch_filter
  );
  $max_build_date = $result -> fetch_assoc();
  $max_build_date = $max_build_date['max_build_date'];

  $result = mysql_run_query(
    "SELECT `binary_packages`.`pkgname`," .
    "`binary_packages`.`epoch`," .
    "`binary_packages`.`pkgver`," .
    "`binary_packages`.`pkgrel`," .
    "`binary_packages`.`sub_pkgrel`," .
    "`binary_packages`.`sub_pkgrel_omitted`," .
    "`architectures`.`name` AS `architecture`," .
    "`repositories`.`name` AS `repo`," .
    "`r_a`.`name` AS `r_a`," .
    "`binary_packages_in_repositories`.`last_moved`" .
    " FROM `binary_packages`" .
    mysql_join_binary_packages_binary_packages_in_repositories() .
    mysql_join_binary_packages_in_repositories_repositories() .
    mysql_join_repositories_architectures("", "r_a") .
    mysql_join_binary_packages_architectures() .
    " WHERE " . $action_filter . $repo_filter . $arch_filter .
    " ORDER BY `binary_packages_in_repositories`.`last_moved` DESC" .
    " LIMIT 50"
  );
  $packages = array();
  while ($row = $result -> fetch_assoc())
    $packages[] = $row;

  header('Content-Type: application/rss+xml; charset=utf-8');

  print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
  print "<rss version=\"2.0\">";
  print "<channel>";
  print "<title>";
  print "Arch Linux 32: ";
  switch ($action) {
    case '':
      print "Recent package updates";
      break;
    case 'added':
      print "Recent added packages";
      break;
    case 'removes':
      print "Recent removed packages";
      break;
  }
  if ($arch != 'all')
    print " (" . $arch;
  if ($repo != '')
    print " [" . $repo . "]";
  if ($arch != '')
    print ")";
  print "</title>";
  print "<link>";
  print "https://www.archlinux32.org/packages/";
  print "</link>";
  print "<description>";
  switch ($action) {
    case '':
      print "Recently updated packages in the Arch Linux 32 package repositories";
      break;
    case 'added':
      print "Recently added packages to the Arch Linux 32 package repositories";
      break;
    case 'removes':
      print "Recently removed packages from the Arch Linux 32 package repositories";
      break;
  }
  if ($arch != 'all')
    print " for the '" . $arch . "' architecture (including 'any' packages)";
  else
    print " for all architectures";
  if ($repo != '')
    print " in the [" . $repo . "] repository";
  print ".";
  print "</description>";
  print "<atom:link href=\"https://www.archlinux32.org" . $_SERVER['REQUEST_URI'] . "\" rel=\"self\">";
  print "</atom:link>";
  print "<language>";
  print "en-us";
  print "</language>";
  print "<lastBuildDate>";
  print $max_build_date;
  print "</lastBuildDate>";
  foreach ($packages as $package) {
    print "<item>";
    print "<title>";
    print $package['pkgname'];
    if ($package['epoch'] != 0)
      print $package['epoch'] . ":";
    print $package['pkgver'] . "-" . $package['pkgrel'];
    if (!$package['sub_pkgrel_omitted'])
      print '.' . $package['sub_pkgrel'];
    print ' ' . $package['architecture'];
    print "</title>";
    print "<link>";
    print "https://www.archlinux32.org/packages/" . $package['repo'] . "/" . $package['r_a'] . "/" . $package['pkgname'] . "/";
    print "</link>";
// TODO: description
    print "<pubDate>";
    print $package['last_moved'];
    print "</pubDate>";
// TODO: guid
    print "<category>";
    print $package['repo'];
    print "</category>";
    print "<category>";
    print $package['r_a'];
    print "</category>";
    print "</item>";
  }
  print "</channel>";
  print "</rss>";

  die();

} // packages

throw_http_error(501, "Not Implemented");