Source for file content.searchbot.php

Documentation is available at content.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''botSearchContent' );
  19.  
  20. /**
  21. * Content 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 botSearchContent$text$phrase=''$ordering='' {
  30.     global $my$database;
  31.     global $mosConfig_absolute_path$mosConfig_offset;
  32.  
  33.     $_SESSION['searchword'$text;
  34.  
  35.     $now date"Y-m-d H:i:s"time()+$mosConfig_offset*60*60 );
  36.  
  37.     $text trim$text );
  38.     if ($text == ''{
  39.         return array();
  40.     }
  41.  
  42.     $wheres array();
  43.     switch ($phrase{
  44.         case 'exact':
  45.             $wheres2 array();
  46.             $wheres2["LOWER(a.title) LIKE '%$text%'";
  47.             $wheres2["LOWER(a.introtext) LIKE '%$text%'";
  48.             $wheres2["LOWER(a.fulltext) LIKE '%$text%'";
  49.             $wheres2["LOWER(a.metakey) LIKE '%$text%'";
  50.             $wheres2["LOWER(a.metadesc) LIKE '%$text%'";
  51.             $where '(' implode') OR ('$wheres2 ')';
  52.             break;
  53.         case 'all':
  54.         case 'any':
  55.         default:
  56.             $words explode' '$text );
  57.             $wheres array();
  58.             foreach ($words as $word{
  59.                 $wheres2 array();
  60.                 $wheres2["LOWER(a.title) LIKE '%$word%'";
  61.                 $wheres2["LOWER(a.introtext) LIKE '%$word%'";
  62.                 $wheres2["LOWER(a.fulltext) LIKE '%$word%'";
  63.                 $wheres2["LOWER(a.metakey) LIKE '%$word%'";
  64.                 $wheres2["LOWER(a.metadesc) LIKE '%$word%'";
  65.                 $wheres[implode' OR '$wheres2 );
  66.             }
  67.             $where '(' implode( ($phrase == 'all' ') AND (' ') OR (')$wheres ')';
  68.             break;
  69.     }
  70.  
  71.     $morder '';
  72.     switch ($ordering{
  73.         case 'newest':
  74.         default:
  75.             $order 'a.created DESC';
  76.             break;
  77.         case 'oldest':
  78.             $order 'a.created ASC';
  79.             break;
  80.         case 'popular':
  81.             $order 'a.hits DESC';
  82.             break;
  83.         case 'alpha':
  84.             $order 'a.title ASC';
  85.             break;
  86.         case 'category':
  87.             $order 'b.title ASC, a.title ASC';
  88.             $morder 'a.title ASC';
  89.             break;
  90.     }
  91.  
  92.     $sql "SELECT a.title AS title,"
  93.     . "\n a.created AS created,"
  94.     . "\n CONCAT(a.introtext, a.fulltext) AS text,"
  95.     . "\n CONCAT_WS( '/', u.title, b.title ) AS section,";
  96.     $sql .= "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id ) AS href,";
  97.     $sql .= "\n '2' AS browsernav"
  98.     . "\n FROM #__content AS a"
  99.     . "\n INNER JOIN #__categories AS b ON b.id=a.catid AND b.access <= '$my->gid'"
  100.     . "\n LEFT JOIN #__sections AS u ON u.id = a.sectionid"
  101.     . "\n WHERE ( $where )"
  102.     . "\n AND a.state = '1'"
  103.     . "\n AND a.access <= '$my->gid'"
  104.     . "\n AND u.published = '1'"
  105.     . "\n AND b.published = '1'"
  106.     . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
  107.     . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
  108.     . "\n ORDER BY $order";
  109.  
  110.     $database->setQuery$sql );
  111.  
  112.     $list $database->loadObjectList();
  113.  
  114.     // search typed content
  115.     $database->setQuery"SELECT a.title AS title, a.created AS created,"
  116.     . "\n a.introtext AS text,"
  117.     . "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id, '&Itemid=', m.id ) AS href,"
  118.     . "\n '2' as browsernav, 'Menu' AS section"
  119.     . "\n FROM #__content AS a"
  120.     . "\n LEFT JOIN #__menu AS m ON m.componentid = a.id"
  121.     . "\n WHERE ($where)"
  122.     . "\n AND a.state='1' AND a.access<='$my->gid' AND m.type='content_typed'"
  123.     . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
  124.     . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
  125.     . "\n ORDER BY " ($morder $morder $order)
  126.     );
  127.     $list2 $database->loadObjectList();
  128.  
  129.     // search archived content
  130.     $database->setQuery"SELECT a.title AS title,"
  131.     . "\n a.created AS created,"
  132.     . "\n a.introtext AS text,"
  133.     . "\n CONCAT_WS( '/', 'Archived ', u.title, b.title ) AS section,"
  134.     . "\n CONCAT('index.php?option=com_content&task=view&id=',a.id) AS href,"
  135.     . "\n '2' AS browsernav"
  136.     . "\n FROM #__content AS a"
  137.     . "\n INNER JOIN #__categories AS b ON b.id=a.catid AND b.access <='$my->gid'"
  138.     . "\n LEFT JOIN #__sections AS u ON u.id = a.sectionid"
  139.     . "\n WHERE ( $where )"
  140.     . "\n AND a.state = '-1' AND a.access <= '$my->gid'"
  141.     . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
  142.     . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
  143.     . "\n ORDER BY $order"
  144.     );
  145.     $list3 $database->loadObjectList();
  146.  
  147.     $result array();
  148.     if ($list$result array_merge($result$list);
  149.     if ($list2$result array_merge($result$list2);
  150.     if ($list3$result array_merge($result$list3);
  151.  
  152.     return $result;
  153. }
  154. ?>

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