PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/sources/subs/Search.subs.php

https://github.com/Arantor/Elkarte
PHP | 66 lines | 27 code | 11 blank | 28 comment | 6 complexity | 8c33cb2bec387934dc57a4e8c003465e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. * Utility functions for search functionality.
  16. *
  17. */
  18. if (!defined('ELKARTE'))
  19. die('No access...');
  20. // This defines two version types for checking the API's are compatible with this version of the software.
  21. $GLOBALS['search_versions'] = array(
  22. // This is the forum version but is repeated due to some people rewriting $forum_version.
  23. 'forum_version' => 'ELKARTE 1.0 Alpha',
  24. // This is the minimum version of ELKARTE that an API could have been written for to work. (strtr to stop accidentally updating version on release)
  25. 'search_version' => strtr('ELKARTE 1+0=Alpha', array('+' => '.', '=' => ' ')),
  26. );
  27. /**
  28. * Creates a search API and returns the object.
  29. *
  30. */
  31. function findSearchAPI()
  32. {
  33. global $modSettings, $search_versions, $searchAPI, $txt;
  34. require_once(SUBSDIR . '/Package.subs.php');
  35. // Search has a special database set.
  36. db_extend('search');
  37. // Load up the search API we are going to use.
  38. $modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index'];
  39. if (!file_exists(SOURCEDIR . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.class.php'))
  40. fatal_lang_error('search_api_missing');
  41. require_once(SOURCEDIR . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.class.php');
  42. // Create an instance of the search API and check it is valid for this version of the software.
  43. $search_class_name = $modSettings['search_index'] . '_search';
  44. $searchAPI = new $search_class_name();
  45. // An invalid Search API.
  46. if (!$searchAPI || ($searchAPI->supportsMethod('isValid') && !$searchAPI->isValid()) || !matchPackageVersion($search_versions['forum_version'], $searchAPI->min_elk_version . '-' . $searchAPI->version_compatible))
  47. {
  48. // Log the error.
  49. loadLanguage('Errors');
  50. log_error(sprintf($txt['search_api_not_compatible'], 'SearchAPI-' . ucwords($modSettings['search_index']) . '.class.php'), 'critical');
  51. require_once(SOURCEDIR . '/SearchAPI-Standard.class.php');
  52. $searchAPI = new Standard_Search();
  53. }
  54. return $searchAPI;
  55. }