1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 Adding OpenSearch to XF

Discussion in 'Styling and Customization Questions' started by Rudy, Nov 13, 2014.

  1. Rudy

    Rudy Well-Known Member

    In order to get the Chrome "tab to search" feature working, and apparently to do similar in other browsers which support it, I'm attempting to add OpenSearch to XF.

    But I've hit a snag. What I know about XML wouldn't fit into a mosquito's antennae.

    From another thread here, I figured out I can do searches via GET by doing the following:

    Code:
    http://forums.xyz.com/index.php?search/search&keywords=my%20search%20term%20here
    I can put that into my address bar and the search actually works fine.

    It's when I get to the XML portion that I hit a snag. First, let me show you how easy it apparently is to implement OpenSearch into a page/site/whatever. This is as simple as adding a file and making one tiny template edit.

    First, you need to create a proper XML document. I named mine opensearch.xml.

    Code:
    <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
    <ShortName>XYZ Forum</ShortName>
    <LongName>Search XYZ Forum</LongName>
    <Description>Search the XYZ Forums</Description>
    <Developer>Joe Developer</Developer>
    <Attribution>Copyright Joe Developer, Inc.</Attribution>
    <AdultContent>false</AdultContent>
    <Language>en-us</Language>
    <InputEncoding>UTF-8</InputEncoding>
    <OutputEncoding>UTF-8</OutputEncoding>
    <Image width="16" height="16" type="image/x-icon">http://www.xyzforum.com/favicon.ico</Image>
    <Url type="text/html" method="GET" template="http://forums.xyz.com/index.php?search/search&keywords={searchTerms}"/>
    </OpenSearchDescription>
    Then, you insert a "link rel" tag into the <head> of your document (in this case, you can add it in the PAGE_CONTAINER template):

    Code:
    <link rel="search" type="application/opensearchdescription+xml" title="XYZ Forums" href="/opensearch.xml" />
    And that is supposed to work.

    However, it seems there is a hiccup in XML. When I try loading the page in the forum, there is no change. If I click on the /opensearch.xml file when I view the page source, Chrome complains about invalid XML.

    upload_2014-11-12_21-29-15.png

    Running through a validation gives me the following:

    upload_2014-11-12_21-33-34.png

    In essence, it's the word "keywords" that must be a reserved word in XML which I cannot use.

    If I can get past that, perhaps this might start working. Is anyone here familiar enough with XML that might know a workaround or edit that would make this XML pass validation?
     
  2. Kevin

    Kevin Well-Known Member

    Here's an example of one that works (at Cool Sci-Fi and other places that I've done at it)...

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <OpenSearchDescription
            xmlns="http://a9.com/-/spec/opensearch/1.1/"
            xmlns:moz="http://www.mozilla.org/2006/browser/search/">
            <ShortName>Cool Sci-Fi</ShortName>
            <Description>Search Cool Sci-Fi, sci-fi and fantasy discussion!</Description>
            <Url type="text/html" method="get" template="http://coolscifi.com/search/1/?q={searchTerms}&amp;o=date" />
            <Url type="application/opensearchdescription+xml" rel="self" template="http://coolscifi.com/opensearch.xml" />
            <Contact>support@coolscifi.com</Contact>
            <Tags>sci-fi forums fantasy horror</Tags>
            <LongName>Cool Sci-Fi Community</LongName>
            <Image height="16" width="16" type="image/x-icon">http://coolscifi.com/favicon.ico</Image>
            <Query role="example" searchTerms="star trek" />
            <Developer>CinVin.com</Developer>
            <Attribution>Search data results copyright CoolSciFi.com</Attribution>
            <SyndicationRight>open</SyndicationRight>
            <AdultContent>false</AdultContent>
            <Language>en-us</Language>
            <Language>en-gb</Language>
            <InputEncoding>UTF-8</InputEncoding>
            <OutputEncoding>UTF-8</OutputEncoding>
    
            <moz:SearchForm>http://coolscifi.com</moz:SearchForm>
    </OpenSearchDescription>
    
    
    And here's the head tag...
    Code:
    <link href="https://coolscifi.com/opensearch.xml" rel="search" title="Cool Sci-Fi" type="application/opensearchdescription+xml" />
     
    Last edited: Nov 13, 2014
    Hoffi likes this.
  3. Rudy

    Rudy Well-Known Member

    It works on other sites as I posted it (with a different search URL template of course), but not on XenForo. However, I think I found something in your code that will help!

    Since "&" is an HTML entity, I need to write out that &amp; in my URL. Going to try that now. That explains why it is balking around the word "keyword" in the URL.

    Thanks!
     
  4. Rudy

    Rudy Well-Known Member

    Sure enough, that made it work, and results come back nicely. I can see it working in Chrome, but...how can you see its results using IE or Firefox? I had no luck in IE11 seeing anything, and Firefox I don't use. If it involves downloads of plugins, then I won't bother with either one.
     
    Last edited: Nov 13, 2014

Share This Page