From 058a866f959d660cee532bd908233f328ca4d481 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 12 Jul 2009 20:20:17 -0400 Subject: [PATCH] move transcript search widget into addon --- .../SearchTranscripts/SearchTranscripts.inc | 67 +++++++++ functions-legacy.php | 64 +++++++++ functions.php | 128 +----------------- 3 files changed, 135 insertions(+), 124 deletions(-) create mode 100644 addons/SearchTranscripts/SearchTranscripts.inc create mode 100644 functions-legacy.php diff --git a/addons/SearchTranscripts/SearchTranscripts.inc b/addons/SearchTranscripts/SearchTranscripts.inc new file mode 100644 index 0000000..81fc28c --- /dev/null +++ b/addons/SearchTranscripts/SearchTranscripts.inc @@ -0,0 +1,67 @@ + __("Search all of your comic posts' transcripts", 'comicpress'))); + + $this->comicpress = $comicpress; + } + + function search_custom_join($join) { + global $wpdb; + if (is_search() && $this->is_search_key()) { + $join = " LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id "; + } + return $join; + } + + function search_custom_where($where) { + global $wp_query, $wp_version, $wpdb; + if (!empty($wp_query->query_vars['s']) && $this->is_search_key()) { + $search = $wp_query->query_vars['s']; + $key = $_GET['key']; + $status = ($wp_version >= 2.1) ? 'post_type = \'post\' AND post_status = \'publish\'' : 'post_status = \'publish\''; + $where = " AND $wpdb->postmeta.meta_key = '$key' AND $wpdb->postmeta.meta_value LIKE '%$search%' AND $status "; + } + return $where; + } + + function search_custom_template($template) { + if (is_search() && $this->is_search_key() && file_exists(get_template_directory() . '/' . $this->custom_template_default)) { + $template = get_template_directory() . '/' . $this->custom_template_default; + } + + if (!$template) { + $template = get_query_template('search'); + } + + return $template; + } + + function is_search_key($key='') { + if (isset($_GET['key'])) { + if (!empty($_GET['key']) || (!empty($key) && ($key = $_GET['key']))) { + return true; + } + } + return false; + } + + function render_widget() { + echo '
  • '; + include(get_template_directory() . '/searchform-transcript.php'); + echo '
  • '; + } +} + +?> \ No newline at end of file diff --git a/functions-legacy.php b/functions-legacy.php new file mode 100644 index 0000000..4b48d62 --- /dev/null +++ b/functions-legacy.php @@ -0,0 +1,64 @@ +/** +* Find a comic file in the filesystem. +* @param string $folder The folder name to search. +* @param string $override_post A WP Post object to use in place of global $post. +* @param string $filter The $comic_filename_filters to use. +* @return string The relative path to the comic file, or false if not found. +*/ +function get_comic_path($folder = 'comic', $override_post = null, $filter = 'default') { + global $post, $comic_filename_filters, $comic_folder, $archive_comic_folder, $rss_comic_folder, $comic_pathfinding_errors; + + if (isset($comic_filename_filters[$filter])) { + $filter_to_use = $comic_filename_filters[$filter]; + } else { + $filter_to_use = '{date}*.*'; + } + + switch ($folder) { + case "rss": $folder_to_use = $rss_comic_folder; break; + case "archive": $folder_to_use = $archive_comic_folder; break; + case "comic": default: $folder_to_use = $comic_folder; break; + } + + $post_to_use = (is_object($override_post)) ? $override_post : $post; + $post_date = mysql2date(CP_DATE_FORMAT, $post_to_use->post_date); + + $filter_with_date = str_replace('{date}', $post_date, $filter_to_use); + + if (count($results = glob("${folder_to_use}/${filter_with_date}")) > 0) { + return reset($results); + } + + $comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the %s folder that matched the pattern %s. Check your WordPress and ComicPress settings.", 'comicpress'), $folder, $filter_with_date); + return false; +} + +/** +* Find a comic file in the filesystem and return an absolute URL to that file. +* @param string $folder The folder name to search. +* @param string $override_post A WP Post object to use in place of global $post. +* @param string $filter The $comic_filename_filters to use. +* @return string The absolute URL to the comic file, or false if not found. +*/ +function get_comic_url($folder = 'comic', $override_post = null, $filter = 'default') { + if (($result = get_comic_path($folder, $override_post, $filter)) !== false) { + return get_option('home') . '/' . $result; + } + + return false; +} + +// ComicPress Template Functions + +function the_comic($filter = 'default') { echo get_comic_url('comic', null, $filter); } + //The following is deprecated... + function comic_display($filter = 'default') { echo get_comic_url('comic', null, $filter); } + +function the_comic_archive($filter = 'default') { echo get_comic_url('archive', null, $filter); } + //The following is deprecated... + function comic_archive($filter = 'default') { echo get_comic_url('archive', null, $filter); } + +function the_comic_rss($filter = 'default') { echo get_comic_url('rss', null, $filter); } + //The following is deprecated... + function comic_rss($filter = 'default') { echo get_comic_url('rss', null, $filter); } + diff --git a/functions.php b/functions.php index bbfa060..a11edd1 100644 --- a/functions.php +++ b/functions.php @@ -83,70 +83,6 @@ function in_comic_category() { return $comicpress->in_comic_category($post->ID); } -/** -* Find a comic file in the filesystem. -* @param string $folder The folder name to search. -* @param string $override_post A WP Post object to use in place of global $post. -* @param string $filter The $comic_filename_filters to use. -* @return string The relative path to the comic file, or false if not found. -*/ -function get_comic_path($folder = 'comic', $override_post = null, $filter = 'default') { - global $post, $comic_filename_filters, $comic_folder, $archive_comic_folder, $rss_comic_folder, $comic_pathfinding_errors; - - if (isset($comic_filename_filters[$filter])) { - $filter_to_use = $comic_filename_filters[$filter]; - } else { - $filter_to_use = '{date}*.*'; - } - - switch ($folder) { - case "rss": $folder_to_use = $rss_comic_folder; break; - case "archive": $folder_to_use = $archive_comic_folder; break; - case "comic": default: $folder_to_use = $comic_folder; break; - } - - $post_to_use = (is_object($override_post)) ? $override_post : $post; - $post_date = mysql2date(CP_DATE_FORMAT, $post_to_use->post_date); - - $filter_with_date = str_replace('{date}', $post_date, $filter_to_use); - - if (count($results = glob("${folder_to_use}/${filter_with_date}")) > 0) { - return reset($results); - } - - $comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the %s folder that matched the pattern %s. Check your WordPress and ComicPress settings.", 'comicpress'), $folder, $filter_with_date); - return false; -} - -/** -* Find a comic file in the filesystem and return an absolute URL to that file. -* @param string $folder The folder name to search. -* @param string $override_post A WP Post object to use in place of global $post. -* @param string $filter The $comic_filename_filters to use. -* @return string The absolute URL to the comic file, or false if not found. -*/ -function get_comic_url($folder = 'comic', $override_post = null, $filter = 'default') { - if (($result = get_comic_path($folder, $override_post, $filter)) !== false) { - return get_option('home') . '/' . $result; - } - - return false; -} - -// ComicPress Template Functions - -function the_comic($filter = 'default') { echo get_comic_url('comic', null, $filter); } - //The following is deprecated... - function comic_display($filter = 'default') { echo get_comic_url('comic', null, $filter); } - -function the_comic_archive($filter = 'default') { echo get_comic_url('archive', null, $filter); } - //The following is deprecated... - function comic_archive($filter = 'default') { echo get_comic_url('archive', null, $filter); } - -function the_comic_rss($filter = 'default') { echo get_comic_url('rss', null, $filter); } - //The following is deprecated... - function comic_rss($filter = 'default') { echo get_comic_url('rss', null, $filter); } - /** * Display the list of Storyline categories. */ @@ -274,27 +210,24 @@ if ( isset( $_GET['randomcomic'] ) ) if ( function_exists('register_sidebar') ) register_sidebar(); +/* function widget_comicpress_calendar() { ?>
  • -
  • - -
  • -
  • Latest Comics

    @@ -430,58 +363,5 @@ function widget_comicpress_comic_bookmark() { ?> register_sidebar_widget(__('Comic Bookmark'), 'widget_comicpress_comic_bookmark'); -/* -Plugin Name: Search Custom Fields -Plugin URI: http://guff.szub.net/search-custom-fields/ -Description: Search post custom field values. Also provides for an alternative theme 'search' template: search-custom.php. -Author: Kaf Oseo -Version: R1.beta1 -Author URI: http://szub.net - Copyright (c) 2006 Kaf Oseo (http://szub.net) - Search Custom Fields is released under the GNU General Public License - (GPL) http://www.gnu.org/licenses/gpl.txt - - This is a WordPress 2 plugin (http://wordpress.org). -*/ - -function szub_search_custom_join($join) { - global $wpdb; - if( is_search() && szub_is_search_key() ) { - $join = " LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id "; - } - return $join; -} -add_filter('posts_join', 'szub_search_custom_join'); - -function szub_search_custom_where($where) { - global $wp_query, $wp_version, $wpdb; - if( !empty($wp_query->query_vars['s']) && szub_is_search_key() ) { - $search = $wp_query->query_vars['s']; - $key = $_GET['key']; - $status = ($wp_version >= 2.1) ? 'post_type = \'post\' AND post_status = \'publish\'' : 'post_status = \'publish\''; - $where = " AND $wpdb->postmeta.meta_key = '$key' AND $wpdb->postmeta.meta_value LIKE '%$search%' AND $status "; - } - return $where; -} -add_filter('posts_where', 'szub_search_custom_where'); - -function szub_search_custom_template($template) { - if( is_search() && szub_is_search_key() && file_exists(TEMPLATEPATH . '/search-transcript.php') ) - $template = TEMPLATEPATH . '/search-transcript.php'; - - if( !$template ) - $template = get_query_template('search'); - return $template; -} -add_filter('search_template', 'szub_search_custom_template'); - -function szub_is_search_key($key='') { - if( isset($_GET['key']) ) { - if( !empty($_GET['key']) || (!empty($key) && ($key = $_GET['key'])) ) - return true; - } - return false; -} - ?>