-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview_docs.php
47 lines (39 loc) · 1.24 KB
/
view_docs.php
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
<?php
require 'functions.php';
# get package id
$pkg_id = $_GET['package'];
# get metadata for package
$handle = fopen("repo/$pkg_id.json", "r");
$pkg = json_decode(fread($handle, filesize("repo/$pkg_id.json")));
if (property_exists($pkg, 'owner')){
$owner = $pkg->owner;
} else {
$owner = 'KarrLab';
}
fclose($handle);
# get URL for documentation
$url = NULL;
if ($owner == 'KarrLab') {
$url = "https://docs.karrlab.org/$pkg_id";
} elseif ($pkg->docs && $pkg->docs->readthedocs) {
$docs_pkg_id = ($pkg->docs->readthedocs->id ? $pkg->docs->readthedocs->id : $pkg->id);
$url = sprintf('https://%s.readthedocs.org', $docs_pkg_id);
} elseif ($pkg->docs && $pkg->docs->url) {
$url = $pkg->docs->url;
} elseif ($pkg->build && $pkg->build->circleci) {
$latest_build = get_latest_build_circleci($owner, $pkg->id, $cache)[0];
$artifacts = get_latest_artifacts_circleci($pkg->id, $latest_build->build_num, $cache);
if ($artifacts['docs']) {
$url = $artifacts['docs'];
}
}
# redirect to URL or return error
if ($url) {
header('Location: '.$url);
exit();
} else {
http_response_code(404);
echo 'No documentation found for package "$pkg_id"';
die();
}
?>