Backend for songs.zachdecook.com
* Suggested Songs: include author name
Zach DeCook 2018-09-30
parent 4a40ec3 · commit dc869d7
-rw-r--r--page.php18
1 files changed, 14 insertions, 4 deletions
diff --git a/page.php b/page.php
index 85b657f..be629d3 100644
--- a/page.php
+++ b/page.php
@@ -2,9 +2,11 @@
/**
* @author: Zach DeCook
* Facilitates loading of tablature and transposition.
- * Copyright (C) 2017 Zach DeCook
+ * Copyright (C) 2017-2018 Zach DeCook
*/
+define( 'AUTHOR_REGEX', "/^-(([A-Za-z.]+ ?)+)/" );
+
/**
* @brief Go through the file inputfile.txt and return each song with a link to it.
*/
@@ -34,7 +36,7 @@ function toc( $sort ){
$entries[$number]['key'] = $matches[1];}
else if( preg_match( "/\{p?\d*\((.+m?)\)\}/", $line, $matches) ){
$entries[$number]['key'] = $matches[1];}
- else if( preg_match( "/^-(([A-Za-z.]+ ?)+)/", $line, $matches) ){
+ else if( preg_match( AUTHOR_REGEX, $line, $matches) ){
$entries[$number]['author'] = $matches[1];}
}fclose($handle);}
@@ -140,6 +142,13 @@ function load_song( $number, $transp = 0 )
$songKey = $matches[1];
}
}
+ if ( isset( $suggestedSong[$current_song] ) )
+ {
+ if ( preg_match( AUTHOR_REGEX, $line, $matches ) )
+ {
+ $suggestedSong[$current_song]['author'] = $matches[1];
+ }
+ }
if ( $current_song === $number || $number == "all" )
{
@@ -231,6 +240,7 @@ function renderSS( $suggestedSong = array(), $songKeys, $transp )
$bs = array();// "bad" songs. Songs without transpositions.
//shuffle( $suggestedSong );
foreach ($suggestedSong as $songNum => $songarray) {
+ $title = $songarray['title'] . ($songarray['author'] ? "($songarray[author])" : '');
if( isset($songarray['key']) )
{
$ok = trim($songarray['key'], 'm');
@@ -243,7 +253,7 @@ function renderSS( $suggestedSong = array(), $songKeys, $transp )
//$xtn = 12/count($songKeys);
//$xtbn = 12;
$s = "<a href='?song=$songNum' class='btn btn-$ok col-md-$bn col-sm-$smbn col-xs-$xsbn'>"
- . "$songarray[title] ($songarray[key])</a>\n";
+ . "$title ($songarray[key])</a>\n";
$classT = "btn col-md-$n col-sm-$smn col-xs-$xsn";
foreach( $songKeys as $sK )
{
@@ -262,7 +272,7 @@ function renderSS( $suggestedSong = array(), $songKeys, $transp )
}
else
{
- $bs[] = "<a href='?song=$songNum' class='btn btn-Z col-xs-12'>$songarray[title]</a>\n";
+ $bs[] = "<a href='?song=$songNum' class='btn btn-Z col-xs-12'>$title</a>\n";
}
}
shuffle( $ss ); shuffle( $bs );