Created
May 16, 2013 15:56
-
-
Save wesleycho/5592804 to your computer and use it in GitHub Desktop.
Why you don't use PHP for templating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php for ($i = 1; $i <= count($tracks); $i++): ?> | |
<div> | |
<ul> | |
<?php for ($j = 1; $j <= count($tracks[$i]); $j++): ?> | |
<li> | |
<?php | |
// Format of $trackName is 1-01 - artist - title - tweak as desired | |
$trackName = $i . '-'; | |
if ($j <= 9) { | |
$trackName .= '0' . $j; | |
} else { | |
$trackName .= $j; | |
} | |
$trackName .= ' - '; | |
for ($k = 0; $k < count($tracks[$i][$j]['artists']); $k++) { | |
if ($k === count($tracks[$i][$j]['artists']) - 1) { | |
$trackName .= $tracks[$i][$j]['artists'][$k] . ' - '; | |
break; | |
} | |
else { | |
$trackName .= $tracks[$i][$j]['artists'][$k] . ', '; | |
} | |
} | |
$trackName .= $tracks[$i][$j]['title']; | |
print $trackName; | |
?><br /> | |
<?php | |
if (count($tracks[$i][$j]['sources']) > 1) { | |
$source = 'Sources: '; | |
for ($k = 0; $k < count($tracks[$i][$j]['sources']); $k++) { | |
if ($k === count($tracks[$i][$j]['sources']) - 1) { | |
$source .= $tracks[$i][$j]['sources'][$k]; | |
break; | |
} | |
else { | |
$source .= $tracks[$i][$j]['sources'][$k] . ', '; | |
} | |
} | |
} | |
else { | |
$source = 'Source: ' . $tracks[$i][$j]['sources'][0]; | |
} | |
print $source; | |
?> | |
<br /> | |
<?php | |
if ((isset($tracks[$i][$j]['credits'])) || (isset($tracks[$i][$j]['lyrics']))) { | |
if (isset($tracks[$i][$j]['credits'])) { ?> | |
<div id="<?php print('credits'.$i.'-'.$j);?>" class="dialog" title="<?php print $trackName; ?>"> | |
<?php | |
for ($k = 0; $k <= count($tracks[$i][$j]['credits']); $k++) { | |
if ($k === count($tracks[$i][$j]['credits']) - 1) { | |
if (is_array($tracks[$i][$j]['credits'][$k])) { ?> | |
<ul> | |
<?php for ($l = 0; $l < count($tracks[$i][$j]['credits'][$k]); $l++): ?> | |
<li><?php print $tracks[$i][$j]['credits'][$k][$l]; ?></li> | |
<?php endfor; ?> | |
</ul> | |
<?php | |
} | |
else { | |
print $tracks[$i][$j]['credits'][$k]; | |
} | |
break; | |
} | |
else { | |
if (is_array($tracks[$i][$j]['credits'][$k])) { ?> | |
<ul> | |
<?php for ($l = 0; $l <= count($tracks[$i][$j]['credits'][$k]); $l++): ?> | |
<li><?php print $tracks[$i][$j]['credits'][$k][$l]; ?></li> | |
<?php endfor; ?> | |
</ul> | |
<?php | |
} | |
else { | |
print $tracks[$i][$j]['credits'][$k] . '<br />'; | |
} | |
} | |
} | |
?> | |
</div> | |
<button id="<?php print('creditsButton'.$i.'-'.$j);?>" class="button blue">Credits</button> | |
<?php | |
} | |
if (isset($tracks[$i][$j]['lyrics'])) { ?> | |
<div id="<?php print('lyrics'.$i.'-'.$j);?>" class="dialog" title="<?php print $trackName; ?>"> | |
<?php | |
if (is_array($tracks[$i][$j]['lyrics'][0])) { | |
for ($k = 0; $k < count($tracks[$i][$j]['lyrics']); $k++) { ?> | |
<h4><?php print $tracks[$i][$j]['lyrics'][$k][0];?></h4> | |
<?php for ($l = 1; $l < count($tracks[$i][$j]['lyrics'][$k]); $l++) { | |
print $tracks[$i][$j]['lyrics'][$k][$l] . '<br />'; | |
} | |
} | |
} | |
else { | |
for ($k = 0; $k < count($tracks[$i][$j]['lyrics']); $k++) { | |
print $tracks[$i][$j]['lyrics'][$k] . '<br />'; | |
} | |
} | |
?> | |
</div> | |
<button id="<?php print('lyricsButton'.$i.'-'.$j);?>" class="button blue">Lyrics</button> | |
<?php | |
} | |
?> | |
<br /> | |
<?php | |
} | |
?> | |
<?php for ($k = 1; $k <= count($downloadMirrors); $k++): ?> | |
<a class="button blue trackButtonMargin" href="<?php print $downloadMirrors[$k] . $tracks[$i][$j]['fileName']; ?>">Mirror <?php print $k ?></a> | |
<?php endfor; ?> | |
</li> | |
<?php endfor; ?> | |
</ul> | |
</div> | |
<?php endfor; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment