Ticket #4231: opensearch.patch

File opensearch.patch, 2.9 KB (added by mythtv@…, 13 years ago)

Patch to allow opensearch calls

  • modules/tv/init.php

     
    3232                                                  'schedules/manual' => t('Schedule Manually'),
    3333                                                  'schedules/custom' => t('Custom Schedule'),
    3434                                                  'recorded'         => t('Recorded Programs'),
     35                                                  'opensearch'       => t('Firefox Search Plugin'),
    3536                                                 ),
    3637                          );
    3738
  • modules/tv/opensearch.php

     
     1<?php
     2/**
     3 * An OpenSearch system for suggesting program names from the firefox toolbar
     4 *
     5 * @url         $$
     6 * @date        $$
     7 * @version     $$
     8 * @author      $$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  TV
     13 *
     14/**/
     15
     16
     17if ($_REQUEST['type'] == 'xml')
     18{
     19header("Content-Type: application/xml");
     20echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
     21?>
     22<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
     23  <ShortName>MythTV</ShortName>
     24  <Description>Search MythTV</Description>
     25  <Url type="application/x-suggestions+json"
     26       method="GET"
     27       template="http://<?php echo $_SERVER["SERVER_NAME"]; echo root?>tv/opensearch?type=suggest&amp;search={searchTerms}">
     28  </Url>
     29  <Url type="text/html"
     30       method="GET"
     31       template="http://<?php echo $_SERVER["SERVER_NAME"]; echo root?>tv/search?type=q&amp;search=Search&amp;s={searchTerms}">
     32  </Url>
     33  <Image height="16" width="16" type="image/png">http://<?php echo $_SERVER["SERVER_NAME"]; echo skin_url ?>img/favicon.ico</Image>
     34</OpenSearchDescription>
     35<?php
     36exit;
     37
     38}
     39
     40if ($_REQUEST['type'] == 'suggest')
     41{
     42if (!isset($_REQUEST['search'])){
     43    echo "ERROR: Must have a search term";
     44    exit;
     45    }
     46
     47$search = $_REQUEST['search'];
     48echo '["'.$search.'",[';
     49
     50$sh = $db->prepare('SELECT DISTINCT title FROM program WHERE title LIKE ? LIMIT 10');
     51$sh->execute($search."%");
     52
     53$middle=0;
     54while ($data =  $sh->fetch_row()){
     55    if ($middle) echo ",";
     56    $middle=1;
     57    $title = $data[0];
     58    $title = addslashes($title);
     59    echo "\"".$title."\"";
     60    }
     61echo "]]";
     62exit;
     63}
     64
     65// Exit
     66    exit;
     67
  • modules/_shared/tmpl/default/header.php

     
    124124    </div>
    125125</div>
    126126
     127<link type="application/opensearchdescription+xml" rel="search" href="<?php echo root ?>tv/opensearch?type=xml" title="MythTV">
    127128
    128129<table width="100%" border="0" cellspacing="2" cellpadding="0">
    129130<tr>