Datei: plugins/example.searchfaq.php
Quellcode
Darstellung:
-
<?php
- /**
- * Plugin example: FAQ search provider
- *
- */
- class FAQSearchExample extends BMPlugin
- {
- function FAQSearchExample()
- {
- $this->name = 'FAQ search example';
- $this->author = 'B1G Software';
- $this->web = 'http://www.b1g.de';
- $this->mail = 'info@b1g.de';
- $this->version = '1.1';
- $this->designedfor = '7.2.0';
- $this->type = BMPLUGIN_DEFAULT;
- }
-
- function GetSearchCategories()
- {
- $result = array();
- $result['FAQSearchExample_FAQ'] = array(
- 'title' => 'FAQ',
- 'icon' => 'ico_faq'
- );
- return($result);
- }
-
- function OnSearch($query)
- {
- global $db, $lang_user;
-
- // prepare
- $results = array();
- $q = '\'%' . $db->Escape($query) . '%\'';
-
- // search FAQ!
- $faqResults = array();
- $res = $db->Query('SELECT id,frage,antwort FROM {pre}faq'
- . ' WHERE (typ=? OR typ=?)'
- . ' AND (frage LIKE ' . $q . ' OR antwort LIKE ' . $q . ')',
- 'li',
- 'both');
- while($row = $res->FetchArray(MYSQL_ASSOC))
- {
- $faqResults[] = array(
- 'icon' => 'ico_faq',
- 'title' => $row['frage'],
- 'link' => 'prefs.php?action=faq&',
- 'id' => $row['id'],
- 'date' => time(),
- 'size' => strlen($row['antwort'])
- );
- }
- $res->Free();
-
- // push FAQ results to results array
- if(count($faqResults) > 0)
- $results[] = array(
- 'title' => $lang_user['faq'],
- 'name' => 'FAQSearchExample_FAQ',
- 'icon' => 'ico_faq',
- 'results' => $faqResults,
- 'massActions' => array(
- 'test' => 'Test'
- )
- );
-
- // return results array
- return($results);
- }
-
- function HandleSearchMassAction($category, $action, $items)
- {
- if($category != 'FAQSearchExample_FAQ')
- return(false);
-
- if($action != 'test')
- return(false);
-
- printf('<script>alert("Selected item IDs: %s");</script>',
- implode(', ', $items));
-
- return(true);
- }
- }
-
- /**
- * register plugin
- */
- $plugins->registerPlugin('FAQSearchExample');
- ?>