about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@gmail.com>2018-04-18 11:51:41 -0400
committerZach DeCook <zachdecook@gmail.com>2018-04-18 11:51:41 -0400
commit35e7deee4b4de0e24e3d9c41a63528114ad209e1 (patch)
tree9e0d65a771745dd125dc5af7100ceb49326b0fad
parent895f7ae639b916287dee4184f3a2a4bdc8424e3e (diff)
downloadprosongsa-35e7deee4b4de0e24e3d9c41a63528114ad209e1.tar.gz
* Index: Detect authors, allow sorting by author.
-rwxr-xr-xindex.php2
-rw-r--r--page.php19
-rw-r--r--sort.php6
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 .= '<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])"; }
 
diff --git a/sort.php b/sort.php
index 4048956..f99b60c 100644
--- a/sort.php
+++ b/sort.php
@@ -12,6 +12,12 @@ function tocTitleSort( $a, $b ){
 	return strcmp( $aTitle, $bTitle );
 }
 
+function tocAuthorSort( $a, $b ){
+	$aTitle = strtolower($a['author']) ?: 'z';
+	$bTitle = strtolower($b['author']) ?: 'z';
+	return strcmp( $aTitle, $bTitle );
+}
+
 define( "BOOK_ORDER", array(
 'Genesis',
 'Exodus',