diff --git a/classes/WDTSDisplayFilters.inc b/classes/WDTSDisplayFilters.inc new file mode 100644 index 0000000..250866d --- /dev/null +++ b/classes/WDTSDisplayFilters.inc @@ -0,0 +1,139 @@ + + + ' . $content . ''); + } + + /** + * Handle the_language_name filter. + * @param string $language The name of the language. + * @return string The processed language name. + */ + function the_language_name($language, $content = "") { + return array($language, '

' . sprintf(apply_filters('the_transcript_format_string'), $language) . '

'); + } + + /** + * Handle showing the header above a bundle of live transcripts. + */ + function the_transcript_language_name($language_format, $code, $content) { + if (is_null($language_format)) { $language_format = apply_filters('the_transcript_format_string', ''); } + + $language_options = new WDTSLanguageOptions(); + + return array($language_format, $code, '

' . sprintf($language_format, $language_options->get_language_name($code)) . '

'); + } + + /** + * The format string used to display ither a single or multiple language transcript header. + */ + function the_transcript_format_string($content) { + return __('Transcript: %s', 'what-did-they-say'); + } + + /** + * The script.aculo.us effects to use when fancy effects are enabled. + */ + function the_transcript_transition_effect($is_opening = true, $content) { + if ($is_opening) { + return array(true, "function(t) { new Effect.BlindDown(t, { duration: 0.25 }); }"); + } else { + return array(false, "function(t) { new Effect.BlindUp(t, { duration: 0.25 }); }"); + } + } + + /** + * 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 ($options['search_integration']) { + 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 ($variable == "end") { ${$variable} += strlen($search_string); } + + 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 . "", trim(substr($transcript['transcript'], $start, $end - $start))); + if ($end_ellipsis) { $output .= "..."; } + + echo $output; + echo '

'; + echo '
'; + } + } + } + } + return array($transcripts, $search_string, ob_get_clean()); + } + + /** + * Filter for dialog short code. + */ + function filter_shortcode_dialog($name, $direction, $speech, $content) { + $content = '
' . $name . ''; + if (!empty($direction)) { + $content .= ' ' . $direction . ''; + } + $content .= ' ' . $speech . '
'; + + return array($name, $direction, $speech, $content); + } + + /** + * Filter for scene heading short code. + */ + function filter_shortcode_scene_heading($description, $content) { + return array($description, '
' . $description . '
'); + } + + /** + * Filter for scene action short code. + */ + function filter_shortcode_scene_action($description, $content) { + return array($description, '
' . $description . '
', ); + } +} + +?> \ No newline at end of file diff --git a/classes/WhatDidTheySayAdmin.inc b/classes/WhatDidTheySayAdmin.inc index 40fd528..9de0f13 100644 --- a/classes/WhatDidTheySayAdmin.inc +++ b/classes/WhatDidTheySayAdmin.inc @@ -7,10 +7,7 @@ class WhatDidTheySayAdmin { var $default_options = array( 'languages' => array( array('code' => 'en', 'default' => true), - 'fr', - 'es', - 'it', - 'de' + 'fr', 'es', 'it', 'de' ), 'capabilities' => array( 'submit_transcriptions' => 'administrator', @@ -28,7 +25,8 @@ class WhatDidTheySayAdmin { 'single' => false ), 'transcript_effects' => false, - 'allow_html' => false + 'allow_html' => false, + 'filters_to_use' => 'simple' ); var $capabilities = array(); @@ -36,6 +34,7 @@ class WhatDidTheySayAdmin { var $language_file; var $all_languages = array(); var $notices = array(); + var $override_filter_info = false; var $is_ajax = false; @@ -46,6 +45,10 @@ class WhatDidTheySayAdmin { function WhatDidTheySayAdmin() { $this->language_file = dirname(__FILE__) . '/../data/lsr-language.txt'; } + + // just in case things need to be unit tested... + function get_filters_dir() { return WP_CONTENT_DIR . '/transcript-filters'; } + function _get_abspath() { return ABSPATH; } /** * Initialize the object. @@ -81,13 +84,52 @@ class WhatDidTheySayAdmin { add_filter('user_has_cap', array(&$this, 'user_has_cap'), 5, 3); // display effects - 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('the_transcript_language_name', array(&$this, 'the_transcript_language_name'), 10, 3); - add_filter('the_transcript_format_string', array(&$this, 'the_transcript_format_string')); - add_filter('the_transcript_opener', array(&$this, 'the_transcript_opener')); - add_filter('the_transcript_transition_effect', array(&$this, 'the_transcript_transition_effect'), 10, 2); + $filters = new WDTSDisplayFilters(); + $reset_filter_value = true; + + if (is_string($options['filters_to_use'])) { + $target = $this->get_filters_dir() . '/' . preg_replace('#[^a-z0-9_-]#', '', strtolower($options['filters_to_use'])); + if (is_dir($target)) { + $this->override_filter_info = array(); + foreach (glob($target . '/*') as $file) { + if (preg_match('#\.(php|inc)$#', $file) > 0) { $this->override_filter_info['php'] = $file; } + if (preg_match('#\.(css)$#', $file) > 0) { $this->override_filter_info['css'] = $file; } + } + + if (isset($this->override_filter_info['php'])) { + $class_name = preg_replace('#\..*$#', '', basename($this->override_filter_info['php'])); + require_once($this->override_filter_info['php']); + + if (class_exists($class_name)) { + $filters = new $class_name(); + $reset_filter_value = false; + } + } + } + } + + if ($reset_filter_value) { + // $options['filters_to_use'] = false; + } + + foreach (array( + array('the_media_transcript', 2), + array('the_language_name', 2), + array('the_matching_transcript_excerpts', 3), + array('the_transcript_language_name', 3), + array('the_transcript_format_string', 1), + array('the_transcript_opener', 1), + array('the_transcript_transition_effect', 2), + array('filter_shortcode_dialog', 4), + array('filter_shortcode_scene_action', 2), + array('filter_shortcode_scene_heading', 2) + ) as $filter_info) { + list($method, $parameters) = $filter_info; + + if (method_exists($filters, $method)) { + add_filter($method, array(&$filters, $method), 10, $parameters); + } + } // short codes foreach (get_class_methods($this) as $method) { @@ -97,10 +139,6 @@ class WhatDidTheySayAdmin { } } - add_filter('filter_shortcode_dialog', array(&$this, 'filter_shortcode_dialog'), 10, 4); - add_filter('filter_shortcode_scene_action', array(&$this, 'filter_shortcode_scene_action'), 10, 2); - add_filter('filter_shortcode_scene_heading', array(&$this, 'filter_shortcode_scene_heading'), 10, 2); - // search transcripts, too? if ($options['search_integration']) { add_filter('posts_where', array(&$this, 'posts_where')); @@ -165,6 +203,10 @@ class WhatDidTheySayAdmin { wp_enqueue_style('wdts-defaults', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-defaults.css'); } + if (isset($this->override_filter_info['css'])) { + wp_enqueue_style('wdts-override', str_replace(realpath($this->_get_abspath()), '', realpath($this->override_filter_info['css']))); + } + if ($options['transcript_effects']) { wp_enqueue_script('scriptaculous-effects'); } @@ -237,6 +279,10 @@ class WhatDidTheySayAdmin { wp_enqueue_style('wdts-admin', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-admin.css'); wp_enqueue_style('wdts-defaults', plugin_dir_url(dirname(__FILE__)) . 'css/wdts-defaults.css'); + if (isset($this->override_filter_info['css'])) { + wp_enqueue_style('wdts-override', str_replace(realpath($this->_get_abspath()), '', realpath($this->override_filter_info['css']))); + } + wp_enqueue_script('scriptaculous-effects'); wp_enqueue_script('edit-transcripts', plugin_dir_url(dirname(__FILE__)) . 'js/edit-transcripts.js', array('scriptaculous-effects', 'wdts-script')); } @@ -255,113 +301,6 @@ class WhatDidTheySayAdmin { return $content . ob_get_clean(); } - /** - * Build the opener/closer for transcripts. - */ - function the_transcript_opener($content = '') { - ob_start(); ?> - - ' . $content . ''); - } - - /** - * Handle the_language_name filter. - * @param string $language The name of the language. - * @return string The processed language name. - */ - function the_language_name($language, $content = "") { - return array($language, '

' . sprintf(apply_filters('the_transcript_format_string'), $language) . '

'); - } - - /** - * Handle showing the header above a bundle of live transcripts. - */ - function the_transcript_language_name($language_format, $code, $content) { - if (is_null($language_format)) { $language_format = apply_filters('the_transcript_format_string', ''); } - - $language_options = new WDTSLanguageOptions(); - - return array($language_format, $code, '

' . sprintf($language_format, $language_options->get_language_name($code)) . '

'); - } - - /** - * The format string used to display ither a single or multiple language transcript header. - */ - function the_transcript_format_string($content) { - return __('Transcript: %s', 'what-did-they-say'); - } - - /** - * The script.aculo.us effects to use when fancy effects are enabled. - */ - function the_transcript_transition_effect($is_opening = true, $content) { - if ($is_opening) { - return array(true, "function(t) { new Effect.BlindDown(t, { duration: 0.25 }); }"); - } else { - return array(false, "function(t) { new Effect.BlindUp(t, { duration: 0.25 }); }"); - } - } - - /** - * 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 ($options['search_integration']) { - 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 ($variable == "end") { ${$variable} += strlen($search_string); } - - 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 . "", trim(substr($transcript['transcript'], $start, $end - $start))); - if ($end_ellipsis) { $output .= "..."; } - - echo $output; - echo '

'; - echo '
'; - } - } - } - } - return array($transcripts, $search_string, ob_get_clean()); - } - /** Transcript Search Filters **/ @@ -400,7 +339,8 @@ class WhatDidTheySayAdmin { return $join; } - /** Short codes and their filters **/ + + /** Short codes **/ /** * Dialog short code. @@ -414,19 +354,6 @@ class WhatDidTheySayAdmin { return end(apply_filters('filter_shortcode_dialog', $name, $direction, $speech, "")); } - /** - * Filter for dialog short code. - */ - function filter_shortcode_dialog($name, $direction, $speech, $content) { - $content = '
' . $name . ''; - if (!empty($direction)) { - $content .= ' ' . $direction . ''; - } - $content .= ' ' . $speech . '
'; - - return array($name, $direction, $speech, $content); - } - /** * Scene action short code. */ @@ -436,13 +363,6 @@ class WhatDidTheySayAdmin { return end(apply_filters('filter_shortcode_scene_action', $description, "")); } - /** - * Filter for scene action short code. - */ - function filter_shortcode_scene_action($description, $content) { - return array($description, '
' . $description . '
', ); - } - /** * Scene heading short code. */ @@ -452,13 +372,6 @@ class WhatDidTheySayAdmin { return end(apply_filters('filter_shortcode_scene_heading', $description, "")); } - /** - * Filter for scene heading short code. - */ - function filter_shortcode_scene_heading($description, $content) { - return array($description, '
' . $description . '
'); - } - /** Capabilities **/ @@ -696,10 +609,16 @@ class WhatDidTheySayAdmin { if (current_user_can('edit_themes')) { $options = get_option('what-did-they-say-options'); - foreach (array('load_default_styles', 'use_nl2br', 'transcript_effects') as $field) { - $options[$field] = isset($info[$field]); + foreach (array('load_default_styles', 'use_nl2br', 'transcript_effects', 'allow_html') as $field) { $options[$field] = isset($info[$field]); } + $options['excerpt_distance'] = !empty($info['excerpt_distance']) ? $info['excerpt_distance'] : 30; + foreach (array_keys($options['hide_transcript']) as $type) { + $options['hide_transcript'][$type] = isset($info['hide_transcript'][$type]); } - + + if (isset($info['filters_to_use'])) { + $options['filters_to_use'] = preg_replace('#[^a-z0-9_-]#', '', strtolower($info['filters_to_use'])); + } + update_option('what-did-they-say-options', $options); $updated = __('Default styles option updated.', 'what-did-they-say'); } @@ -875,6 +794,24 @@ class WhatDidTheySayAdmin { /** What Did They Say?!? administration screens **/ + function _get_available_override_filters() { + $available_filters = array(); + if (is_dir($this->get_filters_dir())) { + foreach (glob($this->get_filters_dir() . '/*') as $dir) { + if (is_dir($dir)) { + if (basename($dir) == preg_replace('#[^a-z0-9_-]#', '', strtolower(basename($dir)))) { + foreach (glob($dir . '/*') as $file) { + if (preg_match('#^(.*)\.(inc|php)$#', basename($file), $matches) > 0) { + $available_filters[] = basename($dir); + } + } + } + } + } + } + return $available_filters; + } + /** * Show the admin page. */ @@ -884,10 +821,12 @@ class WhatDidTheySayAdmin { $options = get_option('what-did-they-say-options'); $nonce = wp_create_nonce('what-did-they-say'); - $transcript_count = (int)$wpdb->get_var($wpdb->prepare("SELECT count($wpdb->postmeta.meta_key) FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'approved_transcripts'")); - - $suggested_amount = 20 + ($transcript_count * 0.1); + $transcript_count = (int)$wpdb->get_var($wpdb->prepare("SELECT count($wpdb->postmeta.meta_key) FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'approved_transcripts'")); + $suggested_amount = 20 + ($transcript_count * 0.1); + + $available_filters = $this->_get_available_override_filters(); + include('partials/admin.inc'); } diff --git a/classes/partials/_default-styles.inc b/classes/partials/_default-styles.inc index 9aa02b7..1b11c30 100644 --- a/classes/partials/_default-styles.inc +++ b/classes/partials/_default-styles.inc @@ -63,6 +63,19 @@ + + + + + diff --git a/what-did-they-say.pot b/what-did-they-say.pot index 3181cc3..dbe63d7 100644 --- a/what-did-they-say.pot +++ b/what-did-they-say.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: what-did-they-say 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-10-06 07:01-0400\n" +"POT-Creation-Date: 2009-10-06 07:11-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -196,13 +196,20 @@ msgid "" msgstr "" #: classes/partials/_default-styles.inc:36 -msgid "Turn transcript line breaks into HTML new lines (nl2br())" +msgid "" +"Turn transcript line breaks into HTML new lines (uses nl2br())" msgstr "" #: classes/partials/_default-styles.inc:44 msgid "" -"Allow HTML in transcripts. If disabled, only short codes are allowed. Script " -"and style tags are always filtered out." +"Allow HTML in transcripts. If disabled, only short codes are allowed, which " +"is recommended. Script, style, and link tags are " +"always filtered out." +msgstr "" + +#: classes/partials/_default-styles.inc:47 +msgid "By default, transcripts should start hidden on these types of pages:" msgstr "" #: classes/partials/_default-styles.inc:55 @@ -472,8 +479,8 @@ msgstr "" msgid "Capabilities" msgstr "" -#: classes/partials/admin.inc:7 classes/partials/_shortcodes-info.inc:2 -msgid "Shortcodes Info" +#: classes/partials/admin.inc:7 +msgid "Short codes Info" msgstr "" #: classes/partials/admin.inc:8 @@ -487,7 +494,7 @@ msgstr "" #: classes/partials/admin.inc:48 #, php-format -msgid "Might I suggest a $%0.2f donation?" +msgid "Might I suggest a $%1$0.2f donation for your %2$d transcripts?" msgstr "" #: classes/partials/_manage-queued-transcripts.inc:2 @@ -520,6 +527,10 @@ msgstr "" msgid "Change capabilities" msgstr "" +#: classes/partials/_shortcodes-info.inc:2 +msgid "Shortcodes Info" +msgstr "" + #: classes/partials/_shortcodes-info.inc:5 msgid "" "you can easily use these shortcodes with the appropriate buttons above all "