From 35e7deee4b4de0e24e3d9c41a63528114ad209e1 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Wed, 18 Apr 2018 11:51:41 -0400 Subject: * Index: Detect authors, allow sorting by author. --- index.php | 2 +- page.php | 19 +++++++++++++++---- sort.php | 6 ++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 1df2c64..5f64590 100755 --- a/index.php +++ b/index.php @@ -96,7 +96,7 @@ include 'page.php'; $song_number = isset( $_GET['song'] ) ? $_GET['song'] : ''; if( ! $song_number ) { - $sort = ''; + $sort = 'default'; if ( isset( $_GET['sort'] ) ) $sort = $_GET['sort']; echo toc($sort); } 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 .= '

Sort by: default, title, verse

'; + $toc .= '

Sort by: '; + foreach( array( 'default', 'title', 'author', 'verse' ) as $thing ){ + $disabled = ($sort == $thing) ? 'disabled' : ''; + $toc .="$thing"; + } + $toc .= '

'; $toc .= '
'; $toc .= '