[mythtv] [PATCH] Mythweb -- canned queries, HD search,
dup elimination
Brad Templeton
brad+mydev at templetons.com
Mon Feb 28 08:07:59 UTC 2005
Here is a modified form of the earlier patch. It supplants it.
Features included are:
a) A page of "canned" searches -- handy common searches people can do
that is easy to add to. Included is a Movies search (already on
the toolbar but now I recommend moving it here) searches for all
HD shows, HD non-series (ie specials and movies), Specials (like
in regular mythv but broken down music and non-music) and
Science fiction movies. New searches can be trivially added
to includes/canned.php
These searches can be easily bookmarked as well.
b) Support for "nodups" mode. If a search result will have multiple
showings they are all grouped together, and all playtimes are shown,
each with a link, in the appropriate box.
c) As noted, an hd: prefix allowed on searches to search only for HD.
Mostly supplanted by the canned searches
-------------- next part --------------
? Makefile
? handy.php
? includes/canned.php
? themes/Default/handy.php
Index: search.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/search.php,v
retrieving revision 1.17
diff -u -r1.17 search.php
--- search.php 10 Feb 2005 02:56:22 -0000 1.17
+++ search.php 28 Feb 2005 08:03:19 -0000
@@ -11,6 +11,7 @@
// Initialize the script, database, etc.
require_once "includes/init.php";
require_once "includes/sorting.php";
+ require_once "includes/canned.php";
// Load all channels
load_all_channels();
@@ -26,9 +27,11 @@
$_SESSION['search']['search_category_type'] = _or($_GET['search_category_type'], $_POST['search_category_type']);
$_SESSION['search']['search_exact'] = _or($_GET['search_exact'], $_POST['search_exact']);
}
+
+
// Individual search strings for different fields
- elseif ($_GET['title'] || $_GET['subtitle'] || $_GET['description'] || $_GET['category'] || $_GET['category_type'] || $_GET['originalairdate']
- || $_POST['title'] || $_POST['subtitle'] || $_POST['description'] || $_POST['category'] || $_POST['category_type'] || $_POST['originalairdate'] ) {
+ elseif ($_GET['title'] || $_GET['subtitle'] || $_GET['description'] || $_GET['category'] || $_GET['category_type'] || $_GET['originalairdate'] || $_GET['canned']
+ || $_POST['title'] || $_POST['subtitle'] || $_POST['description'] || $_POST['category'] || $_POST['category_type'] || $_POST['originalairdate'] || $_POST['canned'] ) {
unset($_SESSION['search']);
$_SESSION['search']['title'] = _or($_GET['title'], $_POST['title']);
$_SESSION['search']['subtitle'] = _or($_GET['subtitle'], $_POST['subtitle']);
@@ -37,11 +40,16 @@
$_SESSION['search']['category_type'] = _or($_GET['category_type'], $_POST['category_type']);
$_SESSION['search']['originalairdate'] = _or($_GET['originalairdate'], $_POST['originalairdate']);
$_SESSION['search']['search_exact'] = _or($_GET['search_exact'], $_POST['search_exact']);
+ $_SESSION['search']['canned'] = _or($_GET['canned'], $_POST['canned']);
}
+
+// Flags that apply in all cases
+ $nodups = _or($_GET['nodups'], $_POST['nodups']);
+
// Start the query out as an array
$query = array();
- $star_query = '';
+ $extra_query = '';
if ($_SESSION['search']['search_exact'])
$compare = ' = ';
else
@@ -58,9 +66,12 @@
if (preg_match( "/1\\/2|\\.5|-/", $stars[1]))
$starcount += 0.125;
// Add this to the query -- convert european decimal to something mysql can understand
- $star_query = ' AND program.stars >= '.str_replace(',', '.', $starcount);
+ $extra_query = ' AND program.stars >= '.str_replace(',', '.', $starcount);
// Remove the stars from the search string so we can continue looking for other things
$search_str = preg_replace('#(\\*+\s*(1/2\b|0?\.5\b|-)?)\s*#', '', $search_str);
+ } elseif( preg_match( "#^hd:#", $search_str ) ) {
+ $extra_query = ' AND hdtv = 1 ';
+ $search_str = preg_replace( "#^hd(?i):\s*#", '', $search_str );
}
// Regex search?
if (preg_match('#^/(.+)/$#', $search_str, $match)) {
@@ -92,6 +103,17 @@
// Individual-field search is an AND search
$joiner = ' AND ';
// Build the query
+ $cq = $_SESSION['search']['canned'];
+ if ($cq) {
+ if( $Canned[$cq] ) {
+ $query[] = $Canned[$cq];
+ # default nodups on here, unless explicitly set
+ if( $nodups != "0" )
+ $nodups = true;
+ }
+ else
+ $Errors[] = "Unknown Canned query: " . $cq;
+ }
if ($_SESSION['search']['title'])
$query[] = "program.title$compare".search_escape($_SESSION['search']['title']);
if (isset($_SESSION['search']['subtitle']))
@@ -117,7 +139,24 @@
# starttime
# endtime
// Perform the query
- $Results =& load_all_program_data(time(), strtotime('+1 month'), NULL, false, '(('.implode($joiner, $query).')'.$star_query.')');
+ $Results =& load_all_program_data(time(), strtotime('+1 month'), NULL, false, '(('.implode($joiner, $query).')'.$extra_query.')');
+
+ // Remove dups from the results if requested
+ if( $nodups ) {
+ $seen = array(); // program ids already seen
+ foreach( $Results as $dex => $row ) {
+ $uniquer = $row->programid . $row->chanid;
+ if( $seen[$uniquer] ) {
+ // add a new field to the old row
+ $Results[$seen[$uniquer]]->extra_showings[] =
+ $row->starttime;
+ unset( $Results[$dex] );
+ } else {
+ $seen[$uniquer] = $dex;
+ }
+
+ }
+ }
// Sort the results
if (count($Results))
sort_programs($Results, 'search_sortby');
Index: languages/English.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/languages/English.php,v
retrieving revision 1.46
diff -u -r1.46 English.php
--- languages/English.php 16 Feb 2005 04:02:40 -0000 1.46
+++ languages/English.php 28 Feb 2005 08:03:20 -0000
@@ -214,6 +214,15 @@
'Key Bindings' => '',
'MythWeb Settings' => '',
'settings: overview' => 'This is the index page for the configuration settings...<p>It\'s incomplete, and will eventually get some nicer formatting. For now, you can choose from the following:',
+// themes/.../handy.php
+ 'handy: overview' => 'This page contains pre-prepared complex searches in the listings.',
+ 'Movies' => '',
+ 'Movies, 3 1/2 Stars or more' => '',
+ 'Non-Series HDTV' => '',
+ 'All HDTV' => '',
+ 'Music Specials' => '',
+ 'Non-Music Specials' => '',
+ 'Science Fiction Movies' => '',
// themes/.../settings_channels.php
'Please be warned that by altering this table without knowing what you are doing, you could seriously disrupt mythtv functionality.' => '',
// themes/.../settings_keys.php
@@ -241,6 +250,7 @@
'Favorites' => '',
'Manually Schedule' => '',
'Movies' => '',
+ 'Searches' => '',
'MythMusic on the web.' => '',
'MythVideo on the web.' => '',
'MythWeb Weather.' => '',
Index: themes/Default/search.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/themes/Default/search.php,v
retrieving revision 1.20
diff -u -r1.20 search.php
--- themes/Default/search.php 5 Feb 2005 05:07:31 -0000 1.20
+++ themes/Default/search.php 28 Feb 2005 08:03:20 -0000
@@ -129,7 +129,16 @@
<td><?php echo $show->subtitle?></td>
<td><?php echo $show->description?></td>
<td><?php echo $show->channel->channum.' - '.$show->channel->name?></td>
- <td nowrap><?php echo strftime($_SESSION['date_search'], $show->starttime)?></td>
+ <td nowrap><?php
+ echo '<br><a href="program_detail.php?chanid='. $show->chanid.
+ '&starttime='.$show->starttime.'">'.
+ strftime($_SESSION['date_search'], $show->starttime) . '</a>';
+ if( $show->extra_showings )
+ foreach( $show->extra_showings as $showtime )
+ echo '<br><a href="program_detail.php?chanid='.
+ $show->chanid.'&starttime='.$showtime.'">'.
+ strftime($_SESSION['date_search'],$showtime). '</a>';
+ ?></td>
<td nowrap><?php echo nice_length($show->length)?></td>
</tr><?php
$prev_group = $cur_group;
Index: themes/Default/theme.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/themes/Default/theme.php,v
retrieving revision 1.48
diff -u -r1.48 theme.php
--- themes/Default/theme.php 9 Feb 2005 03:35:37 -0000 1.48
+++ themes/Default/theme.php 28 Feb 2005 08:03:21 -0000
@@ -149,6 +149,8 @@
<?/* |
<a href="index.php?mode=favourites"><?php echo t('Favorites') ?></a>*/?>
|
+ <a href="handy.php"><?php echo t('Searches') ?></a>
+ |
<a href="schedule_manually.php"><?php echo t('Manually Schedule') ?></a>
|
<a href="recording_schedules.php"><?php echo t('Recording Schedules') ?></a>
-------------- next part --------------
<?php
/*** ***\
handy.php Last Updated: 2005.01.23 (xris)
An index for handy SQL searches in the listings data
\*** ***/
// Which section are we in?
define('section', 'tv');
// Initialize the script, database, etc.
require_once "includes/init.php";
require_once "includes/canned.php";
// Load the class for this page
require_once theme_dir.'handy.php';
// Create an instance of this page from its theme object
$Page = new Theme_handy();
// Display the page
$Page->print_page($Canned);
// Exit
exit;
?>
-------------- next part --------------
<?php
// The canned searches available to the user
// Note -- all canned names, with underbar translated to space, should
// appear in the translation tables
$Canned["Movies"] = "category_type LIKE 'movie'";
$Canned["Movies,_3_1/2_Stars_or_more"] = "category_type LIKE 'movie' AND program.stars > 0.8";
$Canned["Non-Series_HDTV"] = "hdtv=1 AND category_type != 'series'";
$Canned["All_HDTV"] = "hdtv=1";
$Canned["Non-Music_Specials"] = "showtype LIKE 'special' AND category NOT LIKE 'music%'";
$Canned["Music_Specials"] = "showtype LIKE 'special' AND category LIKE 'music%'";
$Canned["Science_Fiction_Movies"] = "category_type LIKE 'movie' AND category LIKE 'science fiction'";
?>
-------------- next part --------------
<?php
/*** ***\
handy.php Last Updated: 2005.02.21 (xris)
main configuration index
\*** ***/
class Theme_handy extends Theme {
function print_page($canned) {
parent::print_header("MythWeb - Handy Predefined Searches");
?>
<div style="padding: 20px">
<? echo t('handy: overview') ?>
<p><table cellpadding=10>
<?php
foreach( $canned as $ckey => $cvalue ) {
$withspaces = strtr( $ckey, "_", " " );
echo '<tr><td><a href="search.php?canned=' . $ckey . '">'.
t($withspaces) . '</a></td></tr>';
}
?>
</table>
</div>
<?php
$this->print_footer();
}
function print_footer() {
parent::print_footer();
}
}
?>
More information about the mythtv-dev
mailing list