PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/snippets/ajaxSearch/ajaxSearchPopup.php

https://github.com/garryn/evolution
PHP | 61 lines | 42 code | 5 blank | 14 comment | 12 complexity | a7b3bd64ddfd7268e38830e53dc9f219 MD5 | raw file
  1. <?php
  2. /** ---------------------------------------------------------------------------
  3. * Snippet: AjaxSearch
  4. * -----------------------------------------------------------------------------
  5. * ajaxSearchPopup.php
  6. *
  7. * @author Coroico - www.modx.wangba.fr
  8. * @version 1.9.0
  9. * @date 18/05/2010
  10. *
  11. */
  12. if (isset($_POST['search'])) {
  13. define('AS_VERSION', '1.9.0');
  14. define('AS_SPATH', 'assets/snippets/ajaxSearch/');
  15. define('AS_PATH', MODX_BASE_PATH . AS_SPATH);
  16. require_once (MODX_MANAGER_PATH . '/includes/protect.inc.php');
  17. if (!isset($_POST['as_version']) || ($_POST['as_version'] != AS_VERSION)) {
  18. $output = "AjaxSearch version obsolete. <br />Please check the snippet code in MODx manager.";
  19. }
  20. else {
  21. include_once AS_PATH . "classes/ajaxSearch.class.inc.php";
  22. define('MODX_API_MODE', true);
  23. include_once (MODX_MANAGER_PATH . '/includes/document.parser.class.inc.php');
  24. $modx = new DocumentParser;
  25. $modx->db->connect();
  26. $modx->getSettings();
  27. startCMSSession();
  28. $tstart = $modx->getMicroTime();
  29. $default = AS_PATH . 'configs/default.config.php';
  30. if (file_exists($default)) include $default;
  31. else return "<h3>AjaxSearch error: $default not found !<br />Check the existing of this file!</h3>";
  32. if (!isset($dcfg)) return "<h3>AjaxSearch error: default configuration array not defined in $default!<br /> Check the content of this file!</h3>";
  33. $ucfg = parseUserConfig($_POST['ucfg']);
  34. // Load the custom functions of the custom configuration file if needed
  35. if ($ucfg['config']) {
  36. $config = $ucfg['config'];
  37. $lconfig = (substr($config, 0, 5) != "@FILE") ? AS_PATH . "configs/$config.config.php" : $modx->config['base_path'] . trim(substr($config, 5));
  38. if (file_exists($lconfig)) include $lconfig;
  39. else return "<h3>AjaxSearch error: " . $lconfig . " not found !<br />Check your config parameter or your config file name!</h3>";
  40. }
  41. $as = new AjaxSearch();
  42. $output = $as->run($tstart, $dcfg);
  43. }
  44. echo $output;
  45. }
  46. /*!
  47. * parseUserConfig : parse the non default configuration from string
  48. */
  49. function parseUserConfig($strUcfg) {
  50. $ucfg = array();
  51. $pattern = '/&([^=]*)=`([^`]*)`/';
  52. preg_match_all($pattern, $strUcfg, $out);
  53. foreach ($out[1] as $key => $values) $ucfg[$out[1][$key]] = $out[2][$key];
  54. return $ucfg;
  55. }
  56. ?>