even more cleanup and search field fixes

This commit is contained in:
John Bintz 2009-09-24 07:29:33 -04:00
parent ebb579a968
commit c59275888f
8 changed files with 147 additions and 65 deletions

View File

@ -80,11 +80,20 @@ class WDTSTranscriptManager {
function _update_search_field($transcripts) { function _update_search_field($transcripts) {
if (!empty($this->search_key)) { if (!empty($this->search_key)) {
$search_lines = array(); $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)); 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) { function delete_transcript($language = null) {
return $this->_delete_transcript_by_field('language', $language); return $this->_delete_transcript_by_field('language', $language);
} }

View File

@ -19,6 +19,7 @@ class WhatDidTheySayAdmin {
), ),
'load_default_styles' => true, 'load_default_styles' => true,
'automatic_embedding' => true, 'automatic_embedding' => true,
'search_integration' => true,
'excerpt_distance' => 30 'excerpt_distance' => 30
); );
@ -64,8 +65,10 @@ class WhatDidTheySayAdmin {
add_filter('template_redirect', array(&$this, 'template_redirect')); add_filter('template_redirect', array(&$this, 'template_redirect'));
add_filter('posts_where', array(&$this, 'posts_where')); if ($options['search_integration']) {
add_filter('posts_join', array(&$this, 'posts_join')); add_filter('posts_where', array(&$this, 'posts_where'));
add_filter('posts_join', array(&$this, 'posts_join'));
}
if ($options['automatic_embedding']) { if ($options['automatic_embedding']) {
add_filter('the_content', array(&$this, 'the_content_automatic_embedding'), 15); add_filter('the_content', array(&$this, 'the_content_automatic_embedding'), 15);
@ -230,38 +233,41 @@ class WhatDidTheySayAdmin {
* Handle the_matching_transcript_excerpts. * Handle the_matching_transcript_excerpts.
*/ */
function the_matching_transcript_excerpts($transcripts, $search_string = '', $content = "") { function the_matching_transcript_excerpts($transcripts, $search_string = '', $content = "") {
$options = get_option('what-did-they-say-options');
ob_start(); ob_start();
if (!empty($search_string)) { if ($options['search_integration']) {
$language_options = new WDTSLanguageOptions(); if (!empty($search_string)) {
$options = get_option('what-did-they-say-options'); $language_options = new WDTSLanguageOptions();
$options = get_option('what-did-they-say-options');
foreach ($transcripts as $transcript) { foreach ($transcripts as $transcript) {
if (($pos = strpos($transcript['transcript'], $search_string)) !== false) { if (($pos = strpos($transcript['transcript'], $search_string)) !== false) {
$l = strlen($transcript['transcript']) - 1; $l = strlen($transcript['transcript']) - 1;
echo '<div class="transcript-match">'; echo '<div class="transcript-match">';
echo '<h4>' . sprintf(__("%s transcript excerpt:", 'what-did-they-say'), $language_options->get_language_name($transcript['language'])) . '</h4>'; echo '<h4>' . sprintf(__("%s transcript excerpt:", 'what-did-they-say'), $language_options->get_language_name($transcript['language'])) . '</h4>';
echo '<p>'; echo '<p>';
$start_ellipsis = $end_ellipsis = true; $start_ellipsis = $end_ellipsis = true;
foreach (array( foreach (array(
'start' => -1, 'start' => -1,
'end' => 1 'end' => 1
) as $variable => $direction) { ) as $variable => $direction) {
${$variable} = $pos + ($options['excerpt_distance'] * $direction); ${$variable} = $pos + ($options['excerpt_distance'] * $direction);
if ($variable == "end") { ${$variable} += strlen($search_string); } if ($variable == "end") { ${$variable} += strlen($search_string); }
if (${$variable} < 0) { ${$variable} = 0; $start_ellipsis = false; } if (${$variable} < 0) { ${$variable} = 0; $start_ellipsis = false; }
if (${$variable} > $l) { ${$variable} = $l; $end_ellipsis = false; } if (${$variable} > $l) { ${$variable} = $l; $end_ellipsis = false; }
} }
$output = ""; $output = "";
if ($start_ellipsis) { $output .= "..."; } if ($start_ellipsis) { $output .= "..."; }
$output .= str_replace($search_string, "<strong>" . $search_string . "</strong>", trim(substr($transcript['transcript'], $start, $end - $start))); $output .= str_replace($search_string, "<strong>" . $search_string . "</strong>", trim(substr($transcript['transcript'], $start, $end - $start)));
if ($end_ellipsis) { $output .= "..."; } if ($end_ellipsis) { $output .= "..."; }
echo $output; echo $output;
echo '</p>'; echo '</p>';
echo '</div>'; echo '</div>';
}
} }
} }
} }
@ -526,6 +532,25 @@ class WhatDidTheySayAdmin {
return $updated; 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 = __('<strong>What Did They Say?!?</strong> core options changed.', 'what-did-they-say');
}
return $updated;
}
/** /**
* Read a data file containing all the known languages on Earth. * 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. * 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) { if (strpos($pagenow, "post") === 0) {
add_meta_box( add_meta_box(
'manage-transcriptions', 'manage-transcriptions',
__('Manage Transcriptions', 'what-did-they-say'), __('Manage Transcripts', 'what-did-they-say'),
array(&$this, 'manage_transcriptions_meta_box'), array(&$this, 'manage_transcriptions_meta_box'),
'post', 'post',
'normal', 'normal',

View File

@ -9,23 +9,34 @@
<h3><?php _e('Getting Started', 'what-did-they-say') ?></h3> <h3><?php _e('Getting Started', 'what-did-they-say') ?></h3>
<p> <p>
<?php _e('<strong>What Did They Say?!?</strong> can attempt to embed excerpts into your posts automatically:', 'what-did-they-say') ?> <?php if (current_user_can('manage_options')) { ?>
<form method="post"> <?php _e('<strong>What Did They Say?!?</strong> can attempt to embed excerpts into your posts automatically:', 'what-did-they-say') ?>
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" /> <form method="post">
<input type="hidden" name="wdts[module]" value="automatic-transcripts" /> <input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[module]" value="core-features" />
<?php if ($options['search_integration']) { ?>
<input type="hidden" name="wdts[search_integration]" value="yes" />
<?php } ?>
<label> <label>
<input type="checkbox" <input type="checkbox"
name="wdts[automatic_embedding]" name="wdts[automatic_embedding]"
value="yes" value="yes"
<?php echo $options['automatic_embedding'] ? 'checked="checked"' : '' ?> /> <?php echo $options['automatic_embedding'] ? 'checked="checked"' : '' ?> />
<?php _e('Enable automatic transcript embedding', 'what-did-they-say') ?> <?php _e('Enable automatic transcript embedding', 'what-did-they-say') ?>
</label> </label>
<input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" /> <input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" />
</form> </form>
<?php } else { ?>
<?php if ($options['automatic_embedding']) { ?>
<?php _e('<strong>What Did They Say?!?</strong> is set to attempt to embed excerpts into your posts automatically.', 'what-did-they-say') ?>
<?php } else { ?>
<?php _e('<strong>What Did They Say?!?</strong> will not attempt to embed excerpts into your posts automatically.', 'what-did-they-say') ?>
<?php } ?>
<?php } ?>
</p> </p>
<p> <p>
<?php _e('If the above method doesn\'t work or you desire more control, you can add the following Template Tags to the appropriate location in your posts Loop:', 'what-did-they-say') ?> <?php _e('If the automatic embedding method doesn\'t work or you desire more control, you can add the following Template Tags to the appropriate location in your posts Loop:', 'what-did-they-say') ?>
</p> </p>
<pre> <pre>
@ -38,7 +49,32 @@
<h3><?php _e('Search Results', 'what-did-they-say') ?></h3> <h3><?php _e('Search Results', 'what-did-they-say') ?></h3>
<p> <p>
<?php _e('When someone searches your site, <strong>What Did They Say?!?</strong> will search your transcripts, too.', 'what-did-they-say') ?> <?php _e('When someone searches your site, <strong>What Did They Say?!?</strong> can search your transcripts, too.', 'what-did-they-say') ?>
<?php if (current_user_can('manage_options')) { ?>
<form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[module]" value="core-features" />
<?php if ($options['automatic_embedding']) { ?>
<input type="hidden" name="wdts[automatic_embedding]" value="yes" />
<?php } ?>
<label>
<input type="checkbox"
name="wdts[search_integration]"
value="yes"
<?php echo $options['search_integration'] ? 'checked="checked"' : '' ?> />
<?php _e('Enable transcript search integration', 'what-did-they-say') ?>
</label>
<input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" />
</form>
<?php } else { ?>
<?php if ($options['search_integration']) { ?>
<?php _e('<strong>What Did They Say?!?</strong> is set to search transcripts when your site is searched.', 'what-did-they-say') ?>
<?php } else { ?>
<?php _e('<strong>What Did They Say?!?</strong> will not search transcripts when your site is searched.', 'what-did-they-say') ?>
<?php } ?>
<?php } ?>
<?php _e('If you want transcript excerpts to appear in your search results, add the following Template Tag to your search results Loop:', 'what-did-they-say') ?> <?php _e('If you want transcript excerpts to appear in your search results, add the following Template Tag to your search results Loop:', 'what-did-they-say') ?>
</p> </p>

View File

@ -1,11 +1,11 @@
<?php <?php
$pages = array( $pages = array(
'introduction' => __('Introduction', 'what-did-they-say'), 'introduction' => __('Introduction', 'what-did-they-say'),
'capabilities' => __('Capabilities', 'what-did-they-say'), 'capabilities' => array(__('Capabilities', 'what-did-they-say'), 'edit_users'),
'default-styles' => __('Styles', 'what-did-they-say'), 'default-styles' => array(__('Styles', 'what-did-they-say'), 'edit_themes'),
'change-languages' => __('Languages', 'what-did-they-say'), 'change-languages' => array(__('Languages', 'what-did-they-say'), 'change_languages'),
'shortcodes-info' => __('Shortcodes Info', 'what-did-they-say'), 'shortcodes-info' => array(__('Shortcodes Info', 'what-did-they-say'), 'submit_transcriptions'),
'misc-options' => __('Misc. Options', 'what-did-they-say'), 'misc-options' => array(__('Misc. Options', 'what-did-they-say'), 'manage_options'),
); );
extract($this->plugin_data); extract($this->plugin_data);
@ -14,7 +14,17 @@
<h2><?php _e('What Did They Say?!?', 'what-did-they-say') ?></h2> <h2><?php _e('What Did They Say?!?', 'what-did-they-say') ?></h2>
<div id="wdts-tab-bar"> <div id="wdts-tab-bar">
<?php foreach ($pages as $page => $title) { ?><a id="wdts-tab-<?php echo $page ?>" href="#" class="wdts-tab"><?php echo $title ?></a><?php } ?> <?php foreach ($pages as $page => $title) {
$ok = true;
if (is_array($title)) {
$ok = current_user_can(end($title));
$title = reset($title);
}
if ($ok) {
?><a id="wdts-tab-<?php echo $page ?>" href="#" class="wdts-tab"><?php echo $title ?></a>
<?php }
} ?>
</div> </div>
<div id="wdts-container"> <div id="wdts-container">

View File

@ -47,15 +47,15 @@
<button class="wdts-create" id="wdts-scene-heading">Scene Heading</button> <button class="wdts-create" id="wdts-scene-heading">Scene Heading</button>
<button class="wdts-create" id="wdts-scene-action">Scene Action</button> <button class="wdts-create" id="wdts-scene-action">Scene Action</button>
<button class="wdts-create" id="wdts-dialog">Dialog</button> <button class="wdts-create" id="wdts-dialog">Dialog</button>
</div>
<?php foreach (array_keys($options['languages']) as $code) { <?php foreach (array_keys($options['languages']) as $code) {
$approved_transcript_text = ''; $approved_transcript_text = '';
foreach ($approved_transcripts as $transcript) { foreach ($approved_transcripts as $transcript) {
if ($transcript['language'] == $code) { $approved_transcript_text = $transcript['transcript']; break; } if ($transcript['language'] == $code) { $approved_transcript_text = $transcript['transcript']; break; }
} ?> } ?>
<textarea class="edit-transcript" id="wdts-transcripts-<?php echo $code ?>" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 95%; height: 200px"><?php echo $approved_transcript_text ?></textarea> <textarea class="edit-transcript" id="wdts-transcripts-<?php echo $code ?>" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 99%; height: 200px"><?php echo $approved_transcript_text ?></textarea>
<?php } ?> <?php } ?>
</div>
</p> </p>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -56,5 +56,8 @@
#wdts-shorttags { #wdts-shorttags {
background-color: #DFDFDF; background-color: #DFDFDF;
padding: 3px padding: 3px;
border-radius: 2px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
} }

View File

@ -33,7 +33,6 @@ Event.observe(window, 'load', function() {
[ '#wdts-submit-shorttags button', $('wdts-transcript') ] [ '#wdts-submit-shorttags button', $('wdts-transcript') ]
].each(function(info) { ].each(function(info) {
$$(info[0]).each(function(b) { $$(info[0]).each(function(b) {
top.console.log(b);
b.observe('click', function(e) { b.observe('click', function(e) {
Event.stop(e); Event.stop(e);
var current_transcript = info[1]; var current_transcript = info[1];

View File

@ -87,7 +87,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
$this->w->save_transcript(array( $this->w->save_transcript(array(
'language' => 'en', 'language' => 'en',
'transcript' => 'this is yet another transcript' 'transcript' => '[dialog name="John"]this is yet another transcript[/dialog]'
)); ));
$this->assertEquals( $this->assertEquals(
@ -106,7 +106,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
), ),
array( array(
'language' => 'en', 'language' => 'en',
'transcript' => 'this is yet another transcript', 'transcript' => '[dialog name="John"]this is yet another transcript[/dialog]',
'user_id' => 1, 'user_id' => 1,
'key' => 2 'key' => 2
), ),
@ -114,7 +114,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
get_post_meta(1, $this->w->key, true) get_post_meta(1, $this->w->key, true)
); );
$this->assertEquals("this is another transcript il s'agit d'une nouvelle transcription this is yet another transcript", get_post_meta(1, $this->w->search_key, true)); $this->assertEquals("this is another transcript il s'agit d'une nouvelle transcription John this is yet another transcript", get_post_meta(1, $this->w->search_key, true));
} }
function testDeleteTranscript() { function testDeleteTranscript() {