-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
241 lines (198 loc) · 5.77 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
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
<html>
<head>
<title>iOS App Icon Compare - How does your icon stack up against the rest?</title>
</head>
<body>
<?php
$genreNumbers = array( "Games" => "6014",
"Books" => "6018",
"Business" => "6000",
"Catalogs" => "6022",
"Education" => "6017",
"Entertainment" => "6016",
"Finance" => "6015",
"Food & Drink" => "6023",
"Health & Fitness" => "6013",
"Lifestyle" => "6012",
"Medical" => "6020",
"Music" => "6011",
"Navigation" => "6010",
"News" => "6009",
"Newsstand" => "6021",
"Photo & Video" => "6008",
"Productivity" => "6007",
"Reference" => "6006",
"Social Networking" => "6005",
"Sports" => "6004",
"Travel" => "6003",
"Utilities" => "6002",
"Weather" => "6001",
"* All Genres *" => "nothing"
);
$listIDs = array( "Top Paid Apps" => "toppaidapplications",
"Top Free Apps" => "topfreeapplications",
"Top Grossing Apps" => "topgrossingapplications",
"Top Paid iPad Apps" => "toppaidipadapplications",
"Top Free iPad Apps" => "topfreeipadapplications",
"Top Grossing iPad Apps" => "topgrossingipadapplications"
);
function get_url_contents($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
function iconImageURLsInRSS( $rssString )
{
$theMatches = array();
$theOffset = 0;
$howMany = preg_match_all("/image height[=][\"]75[\"][>](.*)[<]\/im[:]image[>]/", $rssString, $theMatches, PREG_PATTERN_ORDER);
echo( "<!--$howMany app icons-->");
return $theMatches;
}
function getAppNames( $rssString )
{
$theMatches = array();
$theOffset = 0;
$howMany = preg_match_all("/title[>](.*)[<]\/title[>][^<]/", $rssString, $theMatches, PREG_PATTERN_ORDER);
echo( "<!--$howMany app names-->");
return $theMatches;
}
function displayIconGridForIconURL( $localIconURL, $genreID, $listID )
{
$gridWidth = 6;
$gridHeight = 5;
$iconSpacing = 15;
if( $listID == "" )
{
$listID = "toppaidapplications";
}
$rssURL = "https://itunes.apple.com/us/rss/" . $listID . "/limit=100";
if( $genreID != "nothing" )
{
$rssURL .= "/genre=" . $genreID ;
}
$rssURL .= "/xml" ;
echo( "<!-- RSS feed URL: [$rssURL] -->");
$top100GamesRSS = get_url_contents( $rssURL );
$imageMatches = iconImageURLsInRSS( $top100GamesRSS );
$appMatches = getAppNames( $top100GamesRSS );
$imageURLs = $imageMatches[1];
$appNames = $appMatches[1];
$iconURLsToDisplay = array();
$iconAppNamesToDisplay = array();
$howManyIconsToDisplay = $gridHeight * $gridWidth;
$iconsDisplayed = 0;
$localIconIndex = rand( 0, ($howManyIconsToDisplay - 1) );
$iconIndex = rand(0, count($imageURLs) );
for( $whichIcon = 0; $whichIcon < $howManyIconsToDisplay; $whichIcon++ )
{
if( $whichIcon == $localIconIndex )
{
$iconURLsToDisplay["local"] = $localIconURL;
continue;
}
while($iconURLsToDisplay["$iconIndex"] != "" )
{
$iconIndex = rand(0, (count($imageURLs) - 1) );
}
$iconURLsToDisplay["$iconIndex"] = $imageURLs[$iconIndex];
$iconAppNamesToDisplay["$iconIndex"] = $appNames[$iconIndex];
//echo( "<!-- icon $iconIndex is " . $imageURLs[$iconIndex] . ", named " . $appNames[$iconIndex] . "-->\n" );
}
$whichIcon = 0;
?>
<table width="<?php echo ($gridWidth * (75 + $iconSpacing * 2) ); ?>" cellspacing="<?php echo $iconSpacing; ?>" border="0">
<tr>
<?php
foreach( $iconURLsToDisplay as $key => $iconURL )
{
if( $whichIcon % $gridWidth == 0 )
{
echo "</tr>\n<tr>";
}
echo( "<td> <img src=\"$iconURL\" width=75 height=75 border=0 alt=\"" . $iconAppNamesToDisplay[$key] . "\"> </td>\n");
//echo "<!--show icon $whichIcon<br>-->";
$whichIcon++;
}
?>
</tr>
</table>
<?php
}
$iconURL = "";
if( isset($_GET["iconURL"]) )
{
$iconURL = $_GET["iconURL"];
}
$genreID = "";
if( isset($_GET["genre"]))
{
$genreID = $_GET["genre"];
}
$listID = "";
if( isset($_GET["list"]))
{
$listID = $_GET["list"];
}
?>
<h1>Icon Tester</h1>
<h3>Does your app icon stick out amongst some of the most popular apps in your category?</h3>
<p><a href="http://www.idevgames.com/forums/thread-10291.html">Inspired by Seth Willits's comment in this iDevGames thread</a></p>
<form method="get" action="#">
Your icon URL (75x75): <input type="text" size="80" name="iconURL" id="iconURL" value="<?php echo $iconURL;
?>"><br />
Category:
<select name="genre">
<?php
foreach( $genreNumbers as $key => $value )
{
if( $value == $genreID)
{
echo( "<option value=\"$value\" selected=\"yes\">$key</option>/n");
}
else
{
echo( "<option value=\"$value\">$key</option>/n");
}
}
?>
</select><br />
List:
<select name="list">
<?php
foreach( $listIDs as $key => $value )
{
if( $value == $listID)
{
echo( "<option value=\"$value\" selected=\"yes\">$key</option>/n");
}
else
{
echo( "<option value=\"$value\">$key</option>/n");
}
}
?>
</select><br />
<p><i>Data taken from the U.S. charts.</i></p>
<input type="submit" name="Show My Grid" id="Show My Grid" title="Show My Grid">
</form>
<?php
if( isset($_GET["iconURL"]) )
{
if( strlen( $iconURL ) <= 8 )
{
echo "Put in the complete URL of your icon.";
}
else
{
$genreID = $_GET["genre"];
displayIconGridForIconURL($iconURL, $genreID, $listID);
}
}
?>
</body></html>