This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pnsearchapi.php
executable file
·106 lines (94 loc) · 3.19 KB
/
pnsearchapi.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* locations
*
* @copyright (c) 2008,2010, Locations Development Team
* @link http://code.zikula.org/locations
* @author Carsten Volmer
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package locations
*/
/**
* Search plugin info
**/
function locations_searchapi_info()
{
return array('title' => 'locations',
'functions' => array('locations' => 'search'));
}
/**
* Search form component
**/
function locations_searchapi_options($args)
{
if (SecurityUtil::checkPermission( 'locations::', '::', ACCESS_READ)) {
$pnRender = new pnRender('locations');
return $pnRender->fetch('locations_search_options.htm');
}
return '';
}
/**
* Search plugin main function
**/
function locations_searchapi_search($args)
{
$dom = ZLanguage::getModuleDomain('locations');
pnModDBInfoLoad('Search');
$pntable = pnDBGetTables();
$table = $pntable['locations_location'];
$column = $pntable['locations_location_column'];
$searchTable = $pntable['search_result'];
$searchColumn = $pntable['search_result_column'];
$where = search_construct_where($args,
array($column['name']),
null);
$sessionId = session_id();
// define the permission filter to apply
$permFilter = array(array('realm' => 0,
'component_left' => 'location',
'instance_left' => 'locationid',
'instance_right' => '',
'level' => ACCESS_READ));
// get the result set
$objArray = DBUtil::selectObjectArray('locations_location', $where, 'locationid', 1, -1, '', $permFilter);
if ($objArray === false) {
return LogUtil::registerError (__('Error! Could not load items.', $dom));
}
$insertSql = "INSERT INTO $searchTable
( $searchColumn[title],
$searchColumn[text],
$searchColumn[extra],
$searchColumn[created],
$searchColumn[module],
$searchColumn[session])
VALUES ";
// Process the result set and insert into search result table
foreach ($objArray as $obj) {
$desc = $obj['name']. ', ' . $obj['street']. ', ' . $obj['zip']. ' ' . $obj['city'];
$sql = $insertSql . '('
. '\'' . DataUtil::formatForStore($obj['name']) . '\', '
. '\'' . DataUtil::formatForStore($desc) . '\', '
. '\'' . DataUtil::formatForStore($obj['locationid']) . '\', '
. '\'' . DataUtil::formatForStore($obj['cr_date']) . '\', '
. '\'' . 'locations' . '\', '
. '\'' . DataUtil::formatForStore($sessionId) . '\')';
$insertResult = DBUtil::executeSQL($sql);
if (!$insertResult) {
return LogUtil::registerError (__('Error! Could not load items.', $dom));
}
}
return true;
}
/**
* Do last minute access checking and assign URL to items
*
* Access checking is ignored since access check has
* already been done. But we do add a URL to the found item
*/
function locations_searchapi_search_check(&$args)
{
$datarow = &$args['datarow'];
$locid = $datarow['extra'];
$datarow['url'] = pnModUrl('locations', 'user', 'display', array('ot' => 'location', 'locationid' => $locid));
return true;
}