[mythtv] [PATCH] Mythweb -- canned queries, HD search, dup elimination

Brad Templeton brad+mydev at templetons.com
Mon Feb 28 19:21:07 UTC 2005


On Mon, Feb 28, 2005 at 09:26:26AM -0500, James Armstrong wrote:
> >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
> 
> There are two Handy.php files. What file goes where?

My apology, I thought the mailer was including some directory structure

I include a tar file with the 3 new files.  (And the patch again for
convenience)
-------------- 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 @@
                 <?/*&nbsp; | &nbsp;
                 <a href="index.php?mode=favourites"><?php echo t('Favorites') ?></a>*/?>
                 &nbsp; | &nbsp;
+                <a href="handy.php"><?php echo t('Searches') ?></a>
+                &nbsp; | &nbsp;
                 <a href="schedule_manually.php"><?php echo t('Manually Schedule') ?></a>
                 &nbsp; | &nbsp;
                 <a href="recording_schedules.php"><?php echo t('Recording Schedules') ?></a>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: newfiles.tar
Type: application/x-tar
Size: 10240 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20050228/00005389/newfiles.tar


More information about the mythtv-dev mailing list