diff options
| author | Zach DeCook <zachdecook@gmail.com> | 2018-04-18 11:51:41 -0400 |
|---|---|---|
| committer | Zach DeCook <zachdecook@gmail.com> | 2018-04-18 11:51:41 -0400 |
| commit | 35e7deee4b4de0e24e3d9c41a63528114ad209e1 (patch) | |
| tree | 9e0d65a771745dd125dc5af7100ceb49326b0fad /page.php | |
| parent | 895f7ae639b916287dee4184f3a2a4bdc8424e3e (diff) | |
| download | prosongsa-35e7deee4b4de0e24e3d9c41a63528114ad209e1.tar.gz | |
* Index: Detect authors, allow sorting by author.
Diffstat (limited to 'page.php')
| -rw-r--r-- | page.php | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/page.php b/page.php index 38d97ad..f0dcc3d 100644 --- a/page.php +++ b/page.php @@ -25,15 +25,17 @@ function toc( $sort ){ $entries[$number] = array( 'title' => preg_replace("(^(X?C?B?\d+)\. )",'',$line) ); $entries[$number]['number'] = $number; } - if( preg_match("/^{.?Verse: ?(.*)}/i", $line, $matches)){ + else if( preg_match("/^{.?Verse: ?(.*)}/i", $line, $matches)){ if (isset($entries[$number]['verse'])){ $entries[$number]['verse'] .= ", $matches[1]";} else { $entries[$number]['verse'] = $matches[1];} } - if( preg_match("/^{Key: ?(.*)}/i", $line, $matches)){ + else if( preg_match("/^{Key: ?(.*)}/i", $line, $matches)){ $entries[$number]['key'] = $matches[1];} - if( preg_match( "/\{p?\d*\((.+m?)\)\}/", $line, $matches) ){ + else if( preg_match( "/\{p?\d*\((.+m?)\)\}/", $line, $matches) ){ $entries[$number]['key'] = $matches[1];} + else if( preg_match( "/^-(([A-Za-z.]+ ?)+)/", $line, $matches) ){ + $entries[$number]['author'] = $matches[1];} }fclose($handle);} else @@ -41,7 +43,12 @@ function toc( $sort ){ //Error } $toc = ''; - $toc .= '<p>Sort by: <a href="?sort=default">default</a>, <a href="?sort=title">title</a>, <a href="?sort=verse">verse</a></p>'; + $toc .= '<p>Sort by: '; + foreach( array( 'default', 'title', 'author', 'verse' ) as $thing ){ + $disabled = ($sort == $thing) ? 'disabled' : ''; + $toc .="<a class='btn btn-Z $disabled' href='?sort=$thing'>$thing</a>"; + } + $toc .= '</p>'; $toc .= '<form><input type="text" id="toc-filter" placeholder="Filter by song title"/></form>'; $toc .= '<ul id="toc">'; if ( $sort ){ @@ -55,6 +62,9 @@ function toc( $sort ){ else if ( $sort == 'title' ){ usort( $entries, 'tocTitlesort' ); } + else if ( $sort == 'author' ){ + usort( $entries, 'tocAuthorsort' ); + } } foreach( $entries as $item ){ $toc .= tocentry($item); @@ -70,6 +80,7 @@ function tocentry( $item ){ $class = 'incomplete'; } $output = "<li class='$class'><a href=?song=$item[number]>$item[number]. $item[title]</a>"; + if ( $item['author'] ){$output .= "($item[author])";} if ( $item['verse'] ){ $output .= "($item[verse])"; } if ( $item['key'] ){ $output .= "($item[key])"; } |
