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) {
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);
}

View File

@ -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 '<div class="transcript-match">';
echo '<h4>' . sprintf(__("%s transcript excerpt:", 'what-did-they-say'), $language_options->get_language_name($transcript['language'])) . '</h4>';
echo '<p>';
$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 '<div class="transcript-match">';
echo '<h4>' . sprintf(__("%s transcript excerpt:", 'what-did-they-say'), $language_options->get_language_name($transcript['language'])) . '</h4>';
echo '<p>';
$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, "<strong>" . $search_string . "</strong>", 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 '</p>';
echo '</div>';
$output = "";
if ($start_ellipsis) { $output .= "..."; }
$output .= str_replace($search_string, "<strong>" . $search_string . "</strong>", trim(substr($transcript['transcript'], $start, $end - $start)));
if ($end_ellipsis) { $output .= "..."; }
echo $output;
echo '</p>';
echo '</div>';
}
}
}
}
@ -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 = __('<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.
* 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',

View File

@ -9,23 +9,34 @@
<h3><?php _e('Getting Started', 'what-did-they-say') ?></h3>
<p>
<?php _e('<strong>What Did They Say?!?</strong> can attempt to embed excerpts into your posts automatically:', 'what-did-they-say') ?>
<form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[module]" value="automatic-transcripts" />
<?php if (current_user_can('manage_options')) { ?>
<?php _e('<strong>What Did They Say?!?</strong> can attempt to embed excerpts into your posts automatically:', 'what-did-they-say') ?>
<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['search_integration']) { ?>
<input type="hidden" name="wdts[search_integration]" value="yes" />
<?php } ?>
<label>
<input type="checkbox"
name="wdts[automatic_embedding]"
value="yes"
<?php echo $options['automatic_embedding'] ? 'checked="checked"' : '' ?> />
<?php _e('Enable automatic transcript embedding', 'what-did-they-say') ?>
</label>
<input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" />
</form>
<input type="checkbox"
name="wdts[automatic_embedding]"
value="yes"
<?php echo $options['automatic_embedding'] ? 'checked="checked"' : '' ?> />
<?php _e('Enable automatic transcript embedding', 'what-did-they-say') ?>
</label>
<input type="submit" class="button" value="<?php _e('Submit', 'what-did-they-say') ?>" />
</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>
<?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>
<pre>
@ -38,7 +49,32 @@
<h3><?php _e('Search Results', 'what-did-they-say') ?></h3>
<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') ?>
</p>

View File

@ -1,11 +1,11 @@
<?php
$pages = array(
'introduction' => __('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 @@
<h2><?php _e('What Did They Say?!?', 'what-did-they-say') ?></h2>
<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 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-action">Scene Action</button>
<button class="wdts-create" id="wdts-dialog">Dialog</button>
</div>
<?php foreach (array_keys($options['languages']) as $code) {
$approved_transcript_text = '';
foreach ($approved_transcripts as $transcript) {
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>
<?php } ?>
<?php foreach (array_keys($options['languages']) as $code) {
$approved_transcript_text = '';
foreach ($approved_transcripts as $transcript) {
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: 99%; height: 200px"><?php echo $approved_transcript_text ?></textarea>
<?php } ?>
</div>
</p>
<script type="text/javascript">

View File

@ -56,5 +56,8 @@
#wdts-shorttags {
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') ]
].each(function(info) {
$$(info[0]).each(function(b) {
top.console.log(b);
b.observe('click', function(e) {
Event.stop(e);
var current_transcript = info[1];

View File

@ -87,7 +87,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
$this->w->save_transcript(array(
'language' => 'en',
'transcript' => 'this is yet another transcript'
'transcript' => '[dialog name="John"]this is yet another transcript[/dialog]'
));
$this->assertEquals(
@ -106,7 +106,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
),
array(
'language' => 'en',
'transcript' => 'this is yet another transcript',
'transcript' => '[dialog name="John"]this is yet another transcript[/dialog]',
'user_id' => 1,
'key' => 2
),
@ -114,7 +114,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
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() {