diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index 5a4d99c..cc00b11 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -17,7 +17,8 @@ class WhatDidTheySayAdmin { 'approve_transcriptions' => 'administrator', 'change_languages' => 'administrator' ), - 'load_default_styles' => true + 'load_default_styles' => true, + 'excerpt_distance' => 30 ); var $capabilities = array(); @@ -56,8 +57,9 @@ class WhatDidTheySayAdmin { add_action('admin_notices', array(&$this, 'admin_notices')); add_filter('user_has_cap', array(&$this, 'user_has_cap'), 5, 3); - add_filter('the_media_transcript', array(&$this, 'the_media_transcript')); - add_filter('the_language_name', array(&$this, 'the_language_name')); + add_filter('the_media_transcript', array(&$this, 'the_media_transcript'), 10, 2); + add_filter('the_language_name', array(&$this, 'the_language_name'), 10, 2); + add_filter('the_matching_transcript_excerpts', array(&$this, 'the_matching_transcript_excerpts'), 10, 3); add_filter('template_redirect', array(&$this, 'template_redirect')); @@ -80,11 +82,16 @@ class WhatDidTheySayAdmin { $search = get_query_var('s'); if (!empty($search)) { - $where .= $wpdb->prepare(" OR ($wpdb->postmeta.meta_key = %s ", 'approved_transcripts_words'); + $query = $wpdb->prepare(" OR ($wpdb->postmeta.meta_key = %s ", 'approved_transcripts_words'); $search = addslashes_gpc($search); - $where .= " AND $wpdb->postmeta.meta_value LIKE '%$search%') "; + $query .= " AND $wpdb->postmeta.meta_value LIKE '%$search%') "; + + $exact = get_query_var('exact'); + $n = !empty($exact) ? '' : '%'; + + $where = preg_replace("#(\($wpdb->posts.post_title LIKE '{$n}{$search}{$n}'\))#", '\1' . $query, $where); } - + return $where; } @@ -167,8 +174,8 @@ class WhatDidTheySayAdmin { * @param string $transcript The transcription text. * @return string The processed transcription text. */ - function the_media_transcript($transcript) { - return '
'; + $start_ellipsis = $end_ellipsis = true; + foreach (array( + 'start' => -1, + 'end' => 1 + ) as $variable => $direction) { + ${$variable} = $pos + ($options['excerpt_distance'] * $direction); + + if (${$variable} < 0) { ${$variable} = 0; $start_ellipsis = false; } + if (${$variable} > $l) { ${$variable} = $l; $end_ellipsis = false; } + } + + $output = ""; + if ($start_ellipsis) { $output .= "... "; } + $output .= str_replace($search_string, "" . $search_string . "", $transcript['transcript']); + if ($end_ellipsis) { $output .= " ..."; } + + echo $output; + echo '
'; + echo '