forked from LMMS/lmms.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.php
124 lines (108 loc) · 3.12 KB
/
views.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
<?php
require_once('../vendor/autoload.php');
require_once('../lib/RemWiki/RemWiki.php');
require_once('../lib/Releases.php');
/* Documentation page */
function documentationPage($page=null)
{
global $app;
try {
$wiki = new RemWiki\RemWiki(get_protocol() . 'lmms.io/wiki/');
if ($page === null or $page === '') {
$page = 'Main_Page';
}
$json = $wiki->parse($page);
} catch (Exception $e) {
error_log($e);
return $app['twig']->render('errorpage.twig', [
'message' => 'Something went wrong while fetching wiki data',
'code' => '500'
]);
}
return $app['twig']->render('documentation.twig', [
'json' => $json,
'text' => $json['text']['*']
]);
}
/* Downloads page */
function downloadPage()
{
global $app;
try {
$releases = new Releases();
$winstable = [$releases->latestWin32Asset(), $releases->latestWin64Asset()];
$winpre = [$releases->latestWin32Asset(false), $releases->latestWin64Asset(false)];
$osxstable = $releases->latestOSXAssets();
$osxpre = $releases->latestOSXAssets(false);
$linstable = $releases->latestLinuxAssets();
$linpre = $releases->latestLinuxAssets(false);
if ($winstable && $winpre && ($winpre[0]['created_at'] < $winstable[0]['created_at']))
$winpre = null;
if ($osxstable && $osxpre && ($osxpre[0]['created_at'] < $osxstable[0]['created_at']))
$osxpre = null;
if ($linstable && $linpre && ($linpre[0]['created_at'] < $linstable[0]['created_at']))
$linpre = null;
$vars = [
'winstable' => $winstable,
'winpre' => $winpre,
'osxstable' => $osxstable,
'osxpre' => $osxpre,
'linstable' => $linstable,
'linpre' => $linpre
];
} catch (Exception $e) {
error_log($e);
return $app['twig']->render('download/error.twig');
}
return $app['twig']->render('download/index.twig', $vars);
}
require_once('artwork.php');
$app['twig']->addFunction(new Twig_SimpleFunction('create_artwork_item', 'create_artwork_item', ['is_safe' => ['html']]));
function artworkPage()
{
global $app;
return $app['twig']->render('download/artwork.twig');
}
/* Home page */
require_once('utils.php');
$app['twig']->addFunction(new Twig_SimpleFunction('youtube_iframe', 'youtube_iframe', ['is_safe' => ['html']]));
function homePage()
{
global $app;
return $app['twig']->render('home.twig');
}
/*
* Creates an english-readable title from a file name
*/
function humanize_title($filename) {
$replacement = array(
'ss' => '',
'bb' => 'B&B Editor',
'mixer' => 'FX Mixer',
'roll' => 'Roll Editor',
'plugins' => 'Native Instruments',
'automation' => 'Automation Editor',
'vst' => 'VSTi Running via Vestige'
);
$title_split = explode('_', $filename);
$found = false;
foreach($title_split as &$item) {
// Skip 01, 02, etc
if (is_numeric($item)) {
$item = '';
continue;
}
// Substitute array reference with the text above
if (str_contains($item, '.png', false)) {
$item = str_replace('.png', '', $item);
}
if (array_key_exists($item, $replacement)) {
$temp = $replacement[$item];
$item = ($found ? ', ' : ' ') . $temp;
$found = trim($temp) != '' ? true : false;
} else {
$item = ' ' . ucfirst($item);
}
}
return trim(implode('', $title_split));
}