-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
executable file
·142 lines (122 loc) · 3.91 KB
/
index.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
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
<?php
require_once(dirname(__FILE__) . "/index.config.php");
$generatedUrls = array();
global $config;
if ($handle = opendir($config["localPath"])) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && pathinfo($entry, PATHINFO_EXTENSION) == "plist") {
getGeneratedUrls($entry);
}
}
closedir($handle);
}
// Plist parser
function parseValue( $valueNode ) {
$valueType = $valueNode->nodeName;
$transformerName = "parse_$valueType";
if ( is_callable($transformerName) ) {
return call_user_func($transformerName, $valueNode);
}
return null;
}
function parse_integer( $integerNode ) {
return $integerNode->textContent;
}
function parse_string( $stringNode ) {
return $stringNode->textContent;
}
function parse_date( $dateNode ) {
return $dateNode->textContent;
}
function parse_true( $trueNode ) {
return true;
}
function parse_false( $trueNode ) {
return false;
}
function parse_dict( $dictNode ) {
$dict = array();
for (
$node = $dictNode->firstChild;
$node != null;
$node = $node->nextSibling
) {
if ( $node->nodeName == "key" ) {
$key = $node->textContent;
$valueNode = $node->nextSibling;
while ( $valueNode->nodeType == XML_TEXT_NODE ) {
$valueNode = $valueNode->nextSibling;
}
$value = parseValue($valueNode);
$dict[$key] = $value;
}
}
return $dict;
}
function parse_array( $arrayNode ) {
$array = array();
for (
$node = $arrayNode->firstChild;
$node != null;
$node = $node->nextSibling
) {
if ( $node->nodeType == XML_ELEMENT_NODE ) {
array_push($array, parseValue($node));
}
}
return $array;
}
function parsePlist( $path ) {
$document = new DOMDocument();
$document->load($path);
$plistNode = $document->documentElement;
$root = $plistNode->firstChild;
while ( $root->nodeName == "#text" ) {
$root = $root->nextSibling;
}
return parseValue($root);
}
function getGeneratedUrls($plistFile) {
global $config, $generatedUrls;
if ($config["parsePlist"]) {
$plistContent = parsePlist($plistFile);
$ipaUrl = $plistContent["items"][0]["assets"][0]["url"];
$name = $plistContent["items"][0]["metadata"]["title"];
$plistUrl = pathinfo($ipaUrl, PATHINFO_DIRNAME) . "/" . pathinfo($ipaUrl, PATHINFO_FILENAME) . ".plist";
} else {
// non-parsing plist version
global $config, $generatedUrls;
$name = pathinfo($plistFile, PATHINFO_FILENAME);
$plistUrl = $config["baseUrl"] . $name . ".plist";
}
$generatedUrls[$name] = "itms-services://?action=download-manifest&url=" . urlencode($plistUrl);
}
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $config["title"];?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-combined.min.css" rel="stylesheet">
<meta name="author" content="@gunta" />
<meta name="viewport" content="width=320, user-scalable=no, initial-scale=1, maximum-scale=1">
</head>
<body>
<div class="container">
<h2><?php echo $config["title"];?></h2>
<?php if ($lang == "ja") : ?>
<h4>ダウンロードページ</h4>
<p>下記ボタンをタップすると、直接iOSデバイスに<b>インストール</b>されます。</p>
<?php else : ?>
<h4>Download page</h4>
<p>Tap below to Install <b>directly</b> on your iOS device.</p>
<?php endif; ?>
<br />
<?php foreach ($generatedUrls as $linkFilename => $linkUrl) : ?>
<a href="<?php echo $linkUrl; ?>" class="btn btn-large btn-block btn-primary" style="font-weight:bold;" type="button">
<?php echo $linkFilename; ?> <i class="icon-download-alt icon-white"></i></a>
<?php endforeach; ?>
</div>
</body>
</html>