forked from SpaceApi-archive/spaceapiapp_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.php
114 lines (89 loc) · 3.65 KB
/
app.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
<?php
//********************************************************************
// do not edit this section
if(!defined("APPSDIR"))
die("Direct access is not allowed!");
$page->addStylesheet("css/style.css");
$app_dir = APPSDIR . $page->activePage();
$projects = file_get_contents("$app_dir/model.json");
$projects = json_decode($projects);
foreach($projects as $project)
{
$selector_class = preg_replace("/[^a-zA-Z0-9]/i", "_", $project->Title);
$selector_class = strtolower($selector_class);
$page->addInlineStyle('.'. $selector_class .':after { content: "'. $project->Title .'" }');
$html = <<<HTML
<div class="row"><div class="span12">
<div class="spaceapi-box $selector_class">
<div class="row">
<div class="span6" style="padding: 40px 10px 10px 10px; width: 438px;">
<p>$project->Description</p>
<p>
This app was made by %AUTHOR% %TWITTER% %ORGANIZATION%%HOST%.
<!--
there should be no whitespace between the organization
and the host placeholders.
-->
</p>
<p>
%SOURCE%
</p>
</div>
<div class="span6" style="">
<img src="%APPDIR%/img/$project->Screenshot">
</div>
</div>
</div>
</div></div>
HTML;
if(!empty($project->Twitter))
{
$link = '<a href="http://twitter.com/'.$project->Twitter.'" target="_blank">' . $project->Twitter .'</a>';
$html = str_replace("%TWITTER%", "($link)", $html);
}
else
{
$html = str_replace("%TWITTER%", "", $html);
}
switch(true)
{
case !empty($project->Authorsite):
$author = '<a href="'.$project->Authorsite.'" target="_blank">' . $project->Author .'</a>';
break;
// if the author has no private website/blog then his twitter account will be linked
case !empty($project->Twitter):
$author = '<a href="http://twitter.com/'.$project->Twitter.'" target="_blank">' . $project->Author .'</a>';
break;
// if there's no private website nor a twitter account, then ...
default:
$author = $project->Author;
}
$html = str_replace("%AUTHOR%", $author, $html);
if(!empty($project->Organization))
{
$orga = 'from <a href="'. $project->Organizationsite .'" target="_blank">'. $project->Organization .'</a>';
$html = str_replace("%ORGANIZATION%", $orga, $html);
}
else
{
$html = str_replace("%ORGANIZATION%", "", $html);
}
if(!empty($project->Website))
{
$website = str_replace(array("http://", "https://"), array("",""), $project->Website);
$website = preg_replace('/\/.*/', '', $website);
$host = '<a href="'. $project->Website .'" target="_blank">'. $website .'</a>';
$html = str_replace("%HOST%", " and is hosted on $host ", $html);
}
else
{
$html = str_replace("%HOST%", "", $html);
}
$source = "";
if(!empty($project->Github))
$source = '<a href="'.$project->Github.'" target="_blank">Github</a> ';
if(!empty($project->Gitorious))
$source = '<a href="'.$project->Gitorious.'" target="_blank">Gitorious</a> ';
$html = str_replace("%SOURCE%", " The source code is available on $source.", $html);
$page->addContent($html);
}