Source for file weblinks.searchbot.php

Documentation is available at weblinks.searchbot.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @author Mambo Foundation Inc see README.php
  5. @copyright Mambo Foundation Inc.
  6. *  See COPYRIGHT.php for copyright notices and details.
  7. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  8. *  LICENSE.php
  9. *  Mambo is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU General Public License
  11. *  as published by the Free Software Foundation; version 2 of the
  12. *  License.
  13. */
  14.  
  15. /** ensure this file is being included by a parent file */
  16. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  17.  
  18. $_MAMBOTS->registerFunction'onSearch''botSearchWeblinks' );
  19.  
  20. /**
  21. * Web Link Search method
  22. *
  23. * The sql must return the following fields that are used in a common display
  24. * routine: href, title, section, created, text, browsernav
  25. @param string Target search string
  26. @param string mathcing option, exact|any|all
  27. @param string ordering option, newest|oldest|popular|alpha|category
  28. */
  29. function botSearchWeblinks$text$phrase=''$ordering='' {
  30.     global $database$my;
  31.  
  32.     $text trim$text );
  33.     if ($text == ''{
  34.         return array();
  35.     }
  36.     $section     T_('Web Links');
  37.  
  38.     $wheres     array();
  39.     switch ($phrase{
  40.         case 'exact':
  41.             $wheres2 array();
  42.             
  43.             $wheres2["LOWER(a.url) LIKE '%$text%'";
  44.             $wheres2["LOWER(a.description) LIKE '%$text%'";
  45.             $wheres2["LOWER(a.title) LIKE '%$text%'";            
  46.             $where '(' implode') OR ('$wheres2 ')';
  47.             break;
  48.         case 'all':
  49.         case 'any':
  50.         default:
  51.             $words     explode' '$text );
  52.             $wheres array();
  53.             foreach ($words as $word{
  54.                 $wheres2 array();
  55.                   $wheres2[]     "LOWER(a.url) LIKE '%$word%'";
  56.                 $wheres2[]     "LOWER(a.description) LIKE '%$word%'";
  57.                 $wheres2[]     "LOWER(a.title) LIKE '%$word%'";                
  58.                 $wheres[]     implode' OR '$wheres2 );
  59.             }
  60.             $where     '(' implode( ($phrase == 'all' ') AND (' ') OR (')$wheres ')';
  61.             break;
  62.     }    
  63.  
  64.     switch $ordering {
  65.         case 'oldest':
  66.             $order 'a.date ASC';
  67.             break;
  68.         case 'popular':
  69.             $order 'a.hits DESC';
  70.             break;
  71.         case 'alpha':
  72.             $order 'a.title ASC';
  73.             break;
  74.         case 'category':
  75.             $order 'b.title ASC, a.title ASC';
  76.             break;
  77.         case 'newest':
  78.         default:
  79.             $order 'a.date DESC';
  80.     }
  81.  
  82.     $query "SELECT a.title AS title,"
  83.     . "\n a.description AS text,"
  84.     . "\n a.date AS created,"
  85.     . "\n CONCAT_WS( ' / ', '$section', b.title ) AS section,"
  86.     . "\n '1' AS browsernav,"
  87.     . "\n a.url AS href"
  88.     . "\n FROM #__weblinks AS a"
  89.     . "\n INNER JOIN #__categories AS b ON b.id = a.catid AND b.access <= '$my->gid'"
  90.     . "\n WHERE ($where)"
  91.     . "\n ORDER BY $order"
  92.     ;
  93.     $database->setQuery$query );
  94.     $rows $database->loadObjectList();
  95.     return $rows;
  96. }
  97. ?>

Documentation generated on Mon, 05 May 2008 16:24:18 +0400 by phpDocumentor 1.4.0