hooligan

Multi-Tag Search

Nov 13th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 8.81 KB | None | 0 0
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2.  
  3. <product productid="multitagsearch" active="1">
  4.     <title><![CDATA[Multi-Tag Search]]></title>
  5.     <description>Allows search by multiple tags</description>
  6.     <version>1.0</version>
  7.     <url><![CDATA[http://www.vbulletin.org/forum/misc.php?do=producthelp&pid=multitagsearch]]></url>
  8.     <versioncheckurl><![CDATA[http://www.vbulletin.org/forum/misc.php?do=productcheck&pid=multitagsearch]]></versioncheckurl>
  9.     <plugins>
  10.        <plugin active="1" executionorder="5">
  11.             <title><![CDATA[Multi-Tag Search: Fool the invalid tag checker]]></title>
  12.             <hookname>tags_start</hookname>
  13.             <phpcode><![CDATA[if ($vbulletin->options['multitagsearch_active'])
  14. {
  15. if ($_REQUEST['do'] == 'tag')
  16. {
  17.      $multitag = explode(" ", $_REQUEST['tag']);
  18.      $_REQUEST['tag'] = $multitag[0];
  19.      if (substr($_REQUEST['tag'], 0, 1) == '+' OR substr($_REQUEST['tag'], 0, 1) == '-')
  20.      {
  21.            $_REQUEST['tag'] = substr($_REQUEST['tag'], 1, strlen($_REQUEST['tag']));
  22.      }
  23.      
  24.    // we're bypassing the html check so let's make sure we're safe
  25.    $cleantags = array();
  26.    foreach($multitag AS $mtag)
  27.    {
  28.        $cleantags[] = htmlspecialchars_uni(trim(strval($mtag)));
  29.    }
  30.    
  31.    // break the tags up into +/- and unsigned arrays
  32.    $querytags = array();
  33.    $plusquerytags = array();
  34.    $notquerytags = array();
  35.    foreach($cleantags as $mtag)
  36.    {
  37.        if (substr($mtag, 0, 1) == '+')
  38.        {
  39.            $plusquerytags[] = substr($mtag, 1, strlen($mtag));
  40.        }
  41.        elseif (substr($mtag, 0, 1) == '-')
  42.        {
  43.            $notquerytags[] = substr($mtag, 1, strlen($mtag));
  44.        }
  45.        else
  46.        {
  47.            $querytags[] = $mtag;
  48.        }
  49.    }
  50.    
  51.    // check for invalid combinations
  52.    // 1: only minus tags
  53.    if (empty($plusquerytags) AND empty($querytags))
  54.    {
  55.        standard_error(fetch_error('multitagsearch_negativeonly_error'));  
  56.    }
  57. }
  58. }]]></phpcode>
  59.         </plugin>
  60.         <plugin active="1" executionorder="5">
  61.             <title><![CDATA[Multi-Tag Search: Replace the tag search]]></title>
  62.             <hookname>tags_list_query_data</hookname>
  63.             <phpcode><![CDATA[if ($vbulletin->options['multitagsearch_active'])
  64. {        
  65.    // start building the sql
  66.    $multitag_where = '';
  67.    $weight = '';
  68.    $count = 0;
  69.    foreach($querytags as $qtag)
  70.    {
  71.        if (empty($plusquerytags))
  72.        {
  73.            if ($count == 0)
  74.            {
  75.                $multitag_where .= " AND (";
  76.            }
  77.            else
  78.            {
  79.                $multitag_where .= " OR ";
  80.            }
  81.            $multitag_where .= "(taglist REGEXP '[[:<:]]" . $qtag . "[[:>:]]') > 0";
  82.            $count++;
  83.        }        
  84.        if (!empty($weight))
  85.        {
  86.            $weight .= ' + ';
  87.        }
  88.        $weight .= "(taglist REGEXP '[[:<:]]" . $qtag . "[[:>:]]')";
  89.    }
  90.    if (empty($plusquerytags))
  91.    {
  92.        $multitag_where .= ")";
  93.    }
  94.    foreach($plusquerytags as $ptag)
  95.    {
  96.        $multitag_where .= " AND (taglist REGEXP '[[:<:]]" . $ptag . "[[:>:]]') > 0";
  97.        if (!empty($weight))
  98.        {
  99.            $weight .= ' + ';
  100.        }
  101.        $weight .= "(taglist REGEXP '[[:<:]]" . $qtag . "[[:>:]]')";
  102.    }
  103.    $weight = "(" . $weight . ") AS weight ";
  104.    
  105.    // Add the negative tags
  106.    if (!empty($notquerytags))
  107.    {    
  108.        foreach($notquerytags as $ntag)
  109.        {
  110.            $multitag_where .= " AND (taglist REGEXP '[[:<:]]" . $ntag . "[[:>:]]') = 0";
  111.        }
  112.    }
  113.    
  114.    $msql = "SELECT thread.threadid, thread.taglist, $weight, $tachy_columns
  115.         FROM " . TABLE_PREFIX . "thread AS thread
  116.         $tachyjoin
  117.         $hook_query_joins
  118.         WHERE thread.forumid IN(" . implode(', ', $forumids) . ")
  119.             " . ($self_only ? 'AND IF(thread.forumid IN (' . implode(',', $self_only) . '), thread.postuserid = ' . $vbulletin->userinfo['userid'] . ', 1)' : '') . "
  120.             AND thread.visible = 1
  121.             AND thread.sticky IN (0, 1)
  122.             AND thread.open <> 10
  123.             $globalignore
  124.             $hook_query_where
  125.             $multitag_where
  126.         ORDER BY weight DESC, lastpost DESC
  127.         LIMIT " . intval($vbulletin->options['maxresults']);
  128.    
  129.    $threadid_sql = $db->query_read_slave($msql);
  130.  
  131.     $totalthreads = $db->num_rows($threadid_sql);
  132.     if (!$totalthreads)
  133.     {
  134.         standard_error(fetch_error('multitagsearch_noresults_error'));
  135.     }
  136.  
  137.     if ($vbulletin->GPC['pagenumber'] <= 1)
  138.     {
  139.         $db->query_write("INSERT INTO " . TABLE_PREFIX . "tagsearch (tagid, dateline) VALUES ($tag[tagid], " . TIMENOW . ")");
  140.     }
  141.  
  142.     $pagenumber = $vbulletin->GPC['pagenumber'];
  143.     $perpage = $vbulletin->GPC['perpage'];
  144.  
  145.     sanitize_pageresults($totalthreads, $pagenumber, $perpage, 200, $vbulletin->options['maxthreads']);
  146.  
  147.     if ($pagenumber > 1)
  148.     {
  149.         $db->data_seek($threadid_sql, ($pagenumber - 1) * $perpage);
  150.     }
  151.  
  152.     $threadids = array();
  153.     $resultnum = 0;
  154.     while ($thread = $db->fetch_array($threadid_sql))
  155.     {
  156.         $threadids[] = $thread['threadid'];
  157.  
  158.         $resultnum++;
  159.         if ($resultnum >= $perpage)
  160.         {
  161.             break;
  162.         }
  163.     }
  164.     $db->free_result($threadid_sql);
  165.  
  166.     if ($vbulletin->options['threadmarking'] AND $vbulletin->userinfo['userid'])
  167.     {
  168.         // we need this for forum read times
  169.         cache_ordered_forums(1);
  170.     }
  171.  
  172.     // now move on to actual display code
  173.    
  174.     $hook_query_fields = $hook_query_joins = '';
  175. }]]></phpcode>
  176.         </plugin>
  177.         <plugin active="1" executionorder="5">
  178.             <title><![CDATA[Multi-Tag Search: Get ready for display]]></title>
  179.             <hookname>tags_list_threads</hookname>
  180.             <phpcode><![CDATA[if ($vbulletin->options['multitagsearch_active'])
  181. {
  182.    $show['multitags'] = true;
  183. foreach($threads as $key => $mthread)
  184. {
  185.    $tmptags = '';
  186.    $tagarray = explode(",", $mthread['taglist']);
  187.    // trim them
  188.    foreach($tagarray as $tkey => $ttag)
  189.    {
  190.        $tagarray[$tkey] = trim($ttag);
  191.    }
  192.    foreach ($querytags as $qtag)
  193.    {
  194.        if (array_search($qtag, $tagarray) !== false)
  195.        {
  196.            if (!empty($tmptags))
  197.            {
  198.                $tmptags .= ', ';
  199.            }
  200.            $tmptags .= $qtag;
  201.        }
  202.    }
  203.    foreach ($plusquerytags as $ptag)
  204.    {
  205.        if (array_search($ptag, $tagarray) !== false)
  206.        {
  207.            if (!empty($tmptags))
  208.            {
  209.                $tmptags .= ', ';
  210.            }
  211.            $tmptags .= $ptag;
  212.        }
  213.    }
  214.    $threads[$key]['taglist'] = $tmptags;
  215. }
  216. $columncount += 1;
  217.  
  218. if ($vbulletin->options['multitagsearch_autotemplate'])
  219. {
  220.    // add to the tag_search template
  221.    $find = '<td class=\"thead\" width=\"25%\">$vbphrase[forum]</td>';
  222.    $replace = '<if condition=\"$show[multitags]\"><td class=\"thead\" align=\"center\" nowrap=\"nowrap\">$vbphrase[tags]</td></if>';
  223.    $vbulletin->templatecache['tag_search'] = str_replace($find, $find . $replace,  $vbulletin->templatecache['tag_search']);
  224.    
  225.    // add to the threadbit template
  226.    $find = '".(($show[\'inlinemod\']) ? ("';
  227.    $replace = '<if condition=\"$show[multitags]\"><td class=\"alt1\"><div class=\"smallfont\">$thread[taglist]</div></td></if>';
  228.    $vbulletin->templatecache['threadbit'] = str_replace($find, $replace . $find, $vbulletin->templatecache['threadbit']);
  229. }
  230. }]]></phpcode>
  231.              </plugin>
  232.         </plugins>
  233.     <phrases>
  234.         <phrasetype name="Error Messages" fieldname="error">
  235.             <phrase name="multitagsearch_noresults_error" date="0" username="Hambil" version="1.0"><![CDATA[No results found.]]></phrase>
  236.             <phrase name="multitagsearch_negativeonly_error" date="0" username="Hambil" version="1.0"><![CDATA[Search contains only negative tags.]]></phrase>
  237.         </phrasetype>
  238.         <phrasetype name="vBulletin Settings" fieldname="vbsettings">
  239.             <phrase name="setting_multitagsearch_active_desc" date="0" username="" version=""><![CDATA[Set this to yes to make Multi-Tag Search active.]]></phrase>
  240.             <phrase name="setting_multitagsearch_active_title" date="0" username="" version=""><![CDATA[Enable Multi-Tag Search?]]></phrase>
  241.             <phrase name="setting_multitagsearch_autotemplate_desc" date="0" username="" version=""><![CDATA[Set this to yes to use automatic template edits.]]></phrase>
  242.             <phrase name="setting_multitagsearch_autotemplate_title" date="0" username="" version=""><![CDATA[Automatic Template Edits?]]></phrase>
  243.             <phrase name="settinggroup_multitagsearch_settings" date="0" username="" version=""><![CDATA[Multi-Tag Search Settings]]></phrase>
  244.         </phrasetype>
  245.     </phrases>
  246.     <options>
  247.         <settinggroup name="multitagsearch_settings" displayorder="10">
  248.             <setting varname="multitagsearch_active" displayorder="5">
  249.                 <datatype>boolean</datatype>
  250.                 <optioncode>yesno</optioncode>
  251.                 <defaultvalue>1</defaultvalue>
  252.             </setting>
  253.             <setting varname="multitagsearch_autotemplate" displayorder="10">
  254.                 <datatype>boolean</datatype>
  255.                 <optioncode>yesno</optioncode>
  256.                 <defaultvalue>1</defaultvalue>
  257.             </setting>
  258.         </settinggroup>
  259.     </options>
  260. </product>
Advertisement
Add Comment
Please, Sign In to add comment