php define MODX_API_MODE true include_once dirname __FILE__ index 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
define('MODX_API_MODE', true);
include_once(dirname(__FILE__) . "/index.php");
unset($data);
session_start();
$modx->db->connect();
if (empty ($modx->config)) {
$modx->getSettings();
}
$modx->invokeEvent("OnWebPageInit");
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
$modx->sendRedirect($modx->config['site_url']);
}
function getProducts($modxObj)
{
$modx = $modxObj;
$placemk = $_POST['placemk'];
$timemk = $_POST['timemk'];
$typemk = $_POST['typemk'];
$q = $modx->db->query("SELECT sc.id FROM `modx_site_content` sc WHERE `pagetitle`='" . $typemk . "'");
$q = $modx->db->getValue($q);
$maketemp1 = $modx->db->query("CREATE TEMPORARY TABLE `temp1`
SELECT `contentid` FROM `modx_site_tmplvar_contentvalues` WHERE `tmplvarid` = 10
AND `value` LIKE '" . $placemk . "'");
$maketemp2 = $modx->db->query("CREATE TEMPORARY TABLE `temp2`
SELECT `contentid` FROM `modx_site_tmplvar_contentvalues` WHERE `tmplvarid` = 20
AND `value` LIKE '" . $timemk . "'");
$products = $modx->db->query("SELECT sc.id
FROM `temp1`
INNER JOIN `temp2` ON temp1.contentid = temp2.contentid
INNER JOIN `modx_site_content` sc ON temp2.contentid = sc.id
WHERE sc.parent =" . $q . "
AND sc.published=1 AND sc.deleted=0");
$products = $modx->db->getColumn('id', $products);
return implode(",", $products);
}
if (isset($_GET['ajax'])) {
$_SESSION['products'] = getProducts($modx);
$newProducts = preg_replace("(^\\d*,\\d*,\\d*,)", "", $_SESSION['products']);
if ($_SESSION['products'] != '') {
$params['products'] = $_SESSION['products'];
$params['tpl'] = 'item';
$params['dataType'] = 'documents';
$params['renderTVDisplayFormat'] = 1;
$params['display'] = 3;
$params['debug'] = 1;
$params['paginate'] = 0;
$snippet = $modx->runSnippet('catalogView', $params);
echo json_encode(array('html' => $snippet, 'sData' => $_SESSION['data'], 'params'=> $params ));
} else {
}
} else if (isset($_GET["getNext"])) {
$newProducts = preg_replace("(^\\d*,\\d*,\\d*,)", "", $_SESSION['products']);
if ($newProducts === $_SESSION['products']) {
$newProducts = "NULL";
}
$params['products'] = $newProducts;
$_SESSION['products'] = $newProducts;
$params['tpl'] = 'item';
$params['dataType'] = 'documents';
$params['renderTVDisplayFormat'] = 1;
$params['display'] = 3;
$params['debug'] = 1;
$params['paginate'] = 0;
if ($params['products'] != "NULL") {
$snippet = $modx->runSnippet('catalogView', $params);
echo json_encode(array('html' => $snippet, 'sData' => $_SESSION['products'], 'params'=> $params ));
} else {
echo json_encode(array('html' => "NULL", 'sData' => $_SESSION['products'], 'params'=> $params ));
}
}
?>