diff --git a/classes/WDTSTranscript.php b/classes/WDTSTranscript.php index 4709b39..6f841e1 100644 --- a/classes/WDTSTranscript.php +++ b/classes/WDTSTranscript.php @@ -80,11 +80,20 @@ class WDTSTranscriptManager { function _update_search_field($transcripts) { if (!empty($this->search_key)) { $search_lines = array(); - foreach ($transcripts as $transcript) { $search_lines[] = preg_replace('#\[[^\]]+\]#', '', $transcript['transcript']); } + foreach ($transcripts as $transcript) { + $search_lines[] = preg_replace_callback('#\[[^\]]+\]#', array(&$this, '_update_search_field_callback'), $transcript['transcript']); + } update_post_meta($this->post_id, $this->search_key, implode(" ", $search_lines)); } } + function _update_search_field_callback($result) { + $properties = preg_match_all('#[a-z]+="([^\"]+)"#', reset($result), $matches); + $return = ""; + foreach ($matches[1] as $match) { $return .= $match . " "; } + return $return; + } + function delete_transcript($language = null) { return $this->_delete_transcript_by_field('language', $language); } diff --git a/classes/WhatDidTheySayAdmin.php b/classes/WhatDidTheySayAdmin.php index ea86bab..4c9561d 100644 --- a/classes/WhatDidTheySayAdmin.php +++ b/classes/WhatDidTheySayAdmin.php @@ -19,6 +19,7 @@ class WhatDidTheySayAdmin { ), 'load_default_styles' => true, 'automatic_embedding' => true, + 'search_integration' => true, 'excerpt_distance' => 30 ); @@ -63,9 +64,11 @@ class WhatDidTheySayAdmin { add_filter('the_matching_transcript_excerpts', array(&$this, 'the_matching_transcript_excerpts'), 10, 3); add_filter('template_redirect', array(&$this, 'template_redirect')); - - add_filter('posts_where', array(&$this, 'posts_where')); - add_filter('posts_join', array(&$this, 'posts_join')); + + if ($options['search_integration']) { + add_filter('posts_where', array(&$this, 'posts_where')); + add_filter('posts_join', array(&$this, 'posts_join')); + } if ($options['automatic_embedding']) { add_filter('the_content', array(&$this, 'the_content_automatic_embedding'), 15); @@ -230,38 +233,41 @@ class WhatDidTheySayAdmin { * Handle the_matching_transcript_excerpts. */ function the_matching_transcript_excerpts($transcripts, $search_string = '', $content = "") { + $options = get_option('what-did-they-say-options'); ob_start(); - if (!empty($search_string)) { - $language_options = new WDTSLanguageOptions(); - $options = get_option('what-did-they-say-options'); - - foreach ($transcripts as $transcript) { - if (($pos = strpos($transcript['transcript'], $search_string)) !== false) { - $l = strlen($transcript['transcript']) - 1; - echo '
'; - echo '

' . sprintf(__("%s transcript excerpt:", 'what-did-they-say'), $language_options->get_language_name($transcript['language'])) . '

'; - echo '

'; - $start_ellipsis = $end_ellipsis = true; - foreach (array( - 'start' => -1, - 'end' => 1 - ) as $variable => $direction) { - ${$variable} = $pos + ($options['excerpt_distance'] * $direction); + if ($options['search_integration']) { + if (!empty($search_string)) { + $language_options = new WDTSLanguageOptions(); + $options = get_option('what-did-they-say-options'); - if ($variable == "end") { ${$variable} += strlen($search_string); } + foreach ($transcripts as $transcript) { + if (($pos = strpos($transcript['transcript'], $search_string)) !== false) { + $l = strlen($transcript['transcript']) - 1; + echo '

'; + echo '

' . sprintf(__("%s transcript excerpt:", 'what-did-they-say'), $language_options->get_language_name($transcript['language'])) . '

'; + echo '

'; + $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; } - } + if ($variable == "end") { ${$variable} += strlen($search_string); } - $output = ""; - if ($start_ellipsis) { $output .= "..."; } - $output .= str_replace($search_string, "" . $search_string . "", trim(substr($transcript['transcript'], $start, $end - $start))); - if ($end_ellipsis) { $output .= "..."; } + if (${$variable} < 0) { ${$variable} = 0; $start_ellipsis = false; } + if (${$variable} > $l) { ${$variable} = $l; $end_ellipsis = false; } + } - echo $output; - echo '

'; - echo '
'; + $output = ""; + if ($start_ellipsis) { $output .= "..."; } + $output .= str_replace($search_string, "" . $search_string . "", trim(substr($transcript['transcript'], $start, $end - $start))); + if ($end_ellipsis) { $output .= "..."; } + + echo $output; + echo '

'; + echo '
'; + } } } } @@ -526,6 +532,25 @@ class WhatDidTheySayAdmin { return $updated; } + /** + * Handle resettings what-did-they-say-options. + * @param array $info The part of the $_POST array for What Did They Say?!? + * @return string|false A string if a message is to be displayed, or false if no message. + */ + function handle_update_core_features($info) { + $updated = false; + if (current_user_can('manage_options')) { + $options = get_option('what-did-they-say-options'); + foreach (array('automatic_embedding', 'search_integration') as $field) { + $options[$field] = isset($info[$field]); + } + update_option('what-did-they-say-options', $options); + + $updated = __('What Did They Say?!? core options changed.', 'what-did-they-say'); + } + return $updated; + } + /** * Read a data file containing all the known languages on Earth. * The data originally came from http://www.langtag.net/, specifically http://www.langtag.net/registries/lsr-language.txt. @@ -612,7 +637,7 @@ class WhatDidTheySayAdmin { if (strpos($pagenow, "post") === 0) { add_meta_box( 'manage-transcriptions', - __('Manage Transcriptions', 'what-did-they-say'), + __('Manage Transcripts', 'what-did-they-say'), array(&$this, 'manage_transcriptions_meta_box'), 'post', 'normal', diff --git a/classes/partials/_introduction.inc b/classes/partials/_introduction.inc index 5a9151b..aeeb6cc 100644 --- a/classes/partials/_introduction.inc +++ b/classes/partials/_introduction.inc @@ -9,23 +9,34 @@

- What Did They Say?!? can attempt to embed excerpts into your posts automatically:', 'what-did-they-say') ?> -

- - + + What Did They Say?!? can attempt to embed excerpts into your posts automatically:', 'what-did-they-say') ?> + + + + + + - -
+ /> + + + + + + + What Did They Say?!? is set to attempt to embed excerpts into your posts automatically.', 'what-did-they-say') ?> + + What Did They Say?!? will not attempt to embed excerpts into your posts automatically.', 'what-did-they-say') ?> + +

- +

@@ -38,7 +49,32 @@
   

- What Did They Say?!? will search your transcripts, too.', 'what-did-they-say') ?> + What Did They Say?!? can search your transcripts, too.', 'what-did-they-say') ?> + + +

+ + + + + + + +
+ + + What Did They Say?!? is set to search transcripts when your site is searched.', 'what-did-they-say') ?> + + What Did They Say?!? will not search transcripts when your site is searched.', 'what-did-they-say') ?> + + +

diff --git a/classes/partials/admin.inc b/classes/partials/admin.inc index 8d40809..a5e13ea 100644 --- a/classes/partials/admin.inc +++ b/classes/partials/admin.inc @@ -1,11 +1,11 @@ __('Introduction', 'what-did-they-say'), - 'capabilities' => __('Capabilities', 'what-did-they-say'), - 'default-styles' => __('Styles', 'what-did-they-say'), - 'change-languages' => __('Languages', 'what-did-they-say'), - 'shortcodes-info' => __('Shortcodes Info', 'what-did-they-say'), - 'misc-options' => __('Misc. Options', 'what-did-they-say'), + 'capabilities' => array(__('Capabilities', 'what-did-they-say'), 'edit_users'), + 'default-styles' => array(__('Styles', 'what-did-they-say'), 'edit_themes'), + 'change-languages' => array(__('Languages', 'what-did-they-say'), 'change_languages'), + 'shortcodes-info' => array(__('Shortcodes Info', 'what-did-they-say'), 'submit_transcriptions'), + 'misc-options' => array(__('Misc. Options', 'what-did-they-say'), 'manage_options'), ); extract($this->plugin_data); @@ -14,7 +14,17 @@

- $title) { ?> + $title) { + $ok = true; + if (is_array($title)) { + $ok = current_user_can(end($title)); + $title = reset($title); + } + + if ($ok) { + ?> +
diff --git a/classes/partials/meta-box.inc b/classes/partials/meta-box.inc index 09fa211..28db282 100644 --- a/classes/partials/meta-box.inc +++ b/classes/partials/meta-box.inc @@ -47,15 +47,15 @@ -
- - - + + + +