-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathajaxSearchPopup.php
62 lines (55 loc) · 2.52 KB
/
ajaxSearchPopup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/** ---------------------------------------------------------------------------
* Snippet: AjaxSearch
* -----------------------------------------------------------------------------
* ajaxSearchPopup.php
*
* @author Coroico - www.modx.wangba.fr
* @version 1.9.2
* @date 05/12/2010
*
*/
/*!
* parseUserConfig : parse the non default configuration file name from ucfg string
*/
if (!function_exists('parseUserConfig')) {
function parseUserConfig($ucfg) {
preg_match('/&config=`([^`]*)`/', $ucfg, $matches);
return $matches[1];
}
}
if (isset($_POST['search'])) {
define('AS_VERSION', '1.9.2');
define('AS_SPATH', 'assets/snippets/ajaxSearch/');
define('AS_PATH', MODX_BASE_PATH . AS_SPATH);
require_once (MODX_MANAGER_PATH . '/includes/protect.inc.php');
if (!isset($_POST['as_version']) || (strip_tags($_POST['as_version']) != AS_VERSION)) {
$output = "AjaxSearch version obsolete. <br />Please check the snippet code in MODx manager.";
}
else {
include_once AS_PATH . "classes/ajaxSearch.class.inc.php";
define('MODX_API_MODE', true);
include_once (MODX_MANAGER_PATH . '/includes/document.parser.class.inc.php');
$modx = new DocumentParser;
$modx->db->connect();
$modx->getSettings();
startCMSSession();
$tstart = $modx->getMicroTime();
$default = AS_PATH . 'configs/default.config.php';
if (file_exists($default)) include $default;
else return "<h3>AjaxSearch error: $default not found !<br />Check the existing of this file!</h3>";
if (!isset($dcfg)) return "<h3>AjaxSearch error: default configuration array not defined in $default!<br /> Check the content of this file!</h3>";
$config = parseUserConfig((strip_tags($_POST['ucfg'])));
// Load the custom functions of the custom configuration file if needed
if ($config) {
$lconfig = (substr($config, 0, 6) != "@FILE:") ? AS_PATH . "configs/$config.config.php" : $modx->config['base_path'] . trim(substr($config, 6, strlen($config)-6));
if (file_exists($lconfig)) include $lconfig;
else return "<h3>AjaxSearch error: " . $lconfig . " not found !<br />Check your config parameter or your config file name!</h3>";
}
if ($dcfg['version'] != AS_VERSION) return "<h3>AjaxSearch error: Version number mismatch. Check the content of the default configuration file!</h3>";
$as = new AjaxSearch();
$output = $as->run($tstart, $dcfg);
}
echo $output;
}
?>