Datei: plugins/example.searchfaq.php

Quellcode
Darstellung:
  1. <?php
  2. /**
  3.  * Plugin example: FAQ search provider
  4.  *
  5.  */
  6. class FAQSearchExample extends BMPlugin 
  7. {
  8.    function FAQSearchExample()
  9.    {
  10.       $this->name             'FAQ search example';
  11.       $this->author           'B1G Software';
  12.       $this->web              'http://www.b1g.de';
  13.       $this->mail             'info@b1g.de';
  14.       $this->version          '1.1';
  15.       $this->designedfor         '7.2.0';
  16.       $this->type             BMPLUGIN_DEFAULT;
  17.    }
  18.  
  19.    function GetSearchCategories()
  20.    {
  21.       $result = array();
  22.       $result['FAQSearchExample_FAQ'] = array(
  23.          'title'     => 'FAQ',
  24.          'icon'      => 'ico_faq'
  25.       );
  26.       return($result);
  27.    }
  28.    
  29.    function OnSearch($query)
  30.    {
  31.       global $db$lang_user;
  32.       
  33.       // prepare
  34.       $results = array();
  35.       $q '\'%' $db->Escape($query) . '%\'';
  36.       
  37.       // search FAQ!
  38.       $faqResults = array();
  39.       $res $db->Query('SELECT id,frage,antwort FROM {pre}faq'
  40.          .  ' WHERE (typ=? OR typ=?)'
  41.          .  ' AND (frage LIKE ' $q ' OR antwort LIKE ' $q ')',
  42.          'li',
  43.          'both');
  44.       while($row $res->FetchArray(MYSQL_ASSOC))
  45.       {
  46.          $faqResults[] = array(
  47.             'icon'         => 'ico_faq',
  48.             'title'        => $row['frage'],
  49.             'link'         => 'prefs.php?action=faq&',
  50.             'id'        => $row['id'],
  51.             'date'         => time(),
  52.             'size'         => strlen($row['antwort'])
  53.          );
  54.       }
  55.       $res->Free();
  56.       
  57.       // push FAQ results to results array
  58.       if(count($faqResults) > 0)
  59.          $results[] = array(
  60.             'title'        => $lang_user['faq'],
  61.             'name'         => 'FAQSearchExample_FAQ',
  62.             'icon'         => 'ico_faq',
  63.             'results'      => $faqResults,
  64.             'massActions'  => array(
  65.                'test'      => 'Test'
  66.             )
  67.          );
  68.       
  69.       // return results array
  70.       return($results);
  71.    }
  72.  
  73.    function HandleSearchMassAction($category$action$items)
  74.    {
  75.       if($category != 'FAQSearchExample_FAQ')
  76.          return(false);
  77.  
  78.       if($action != 'test')
  79.          return(false);
  80.  
  81.       printf('<script>alert("Selected item IDs: %s");</script>',
  82.          implode(', '$items));
  83.  
  84.       return(true);
  85.    }
  86. }
  87.  
  88. /**
  89.  * register plugin
  90.  */
  91. $plugins->registerPlugin('FAQSearchExample');
  92. ?>