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 0
/
pnsearchapi.php
120 lines (100 loc) · 3.91 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* MediaAttach
*
* @version $Id: pnsearchapi.php 76 2008-03-05 5:43:16Z weckamc $
* @author Axel Guckelsberger
* @link http://guite.de
* @copyright Copyright (C) 2008 by Guite
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
/**
* Search plugin info
**/
function MediaAttach_searchapi_info()
{
return array('title' => 'MediaAttach',
'functions' => array('MediaAttach' => 'search'));
}
/**
* Search form component
**/
function MediaAttach_searchapi_options($args)
{
if (SecurityUtil::checkPermission('MediaAttach::', '::', ACCESS_READ)) {
$render = pnRender::getInstance('MediaAttach');
$render->assign('active', (isset($args['active']) && isset($args['active']['MediaAttach'])) || !isset($args['active']));
return $render->fetch('MediaAttach_search.htm');
}
return '';
}
/**
* Search plugin main function
**/
function MediaAttach_searchapi_search($args)
{
$dom = ZLanguage::getModuleDomain('MediaAttach');
if (!SecurityUtil::checkPermission('MediaAttach::', '::', ACCESS_READ)) {
return true;
}
pnModDBInfoLoad('Search');
$pntable = pnDBGetTables();
$filestable = $pntable['ma_files'];
$filescolumn = $pntable['ma_files_column'];
$searchTable = $pntable['search_result'];
$searchColumn = $pntable['search_result_column'];
$where = search_construct_where($args,
array($filescolumn['title'],
$filescolumn['desc']));
// exclude admin files
$where .= ' AND ' . $filescolumn['modname'] . " != 'MediaAttach'"
. ' AND ' . $filescolumn['objectid'] . " < 99999999";
$sql = 'SELECT ' . $filescolumn['fileid'] . ' AS fileid, '
. $filescolumn['modname'] . ' AS modname, '
. $filescolumn['objectid'] . ' AS objectid,'
. $filescolumn['date'] . ' AS filedate,'
. $filescolumn['title'] . ' AS title, '
. $filescolumn['desc'] . ' AS text, '
. $filescolumn['url'] . ' AS url'
. ' FROM ' . $filestable . ' WHERE ' . $where;
$result = DBUtil::executeSQL($sql);
if (!$result) {
return LogUtil::registerError (__('Error! Could not load items.', $dom));
}
$sessionId = session_id();
$insertSql = 'INSERT INTO ' . $searchTable . '('
. $searchColumn['title'] . ','
. $searchColumn['text'] . ','
. $searchColumn['extra'] . ','
. $searchColumn['module'] . ','
. $searchColumn['created'] . ','
. $searchColumn['session']
. ') VALUES ';
// Process the result set and insert into search result table
for (; !$result->EOF; $result->MoveNext()) {
$file = $result->GetRowAssoc(2);
if (SecurityUtil::checkPermission('MediaAttach::', "$file[modname]:$file[objectid]:$file[fileid]", ACCESS_OVERVIEW)) {
$sql = $insertSql . '('
. '\'' . DataUtil::formatForStore($file['title']) . '\', '
. '\'' . DataUtil::formatForStore($file['text']) . '\', '
. '\'' . DataUtil::formatForStore($file['url']) . '\', '
. '\'' . 'MediaAttach' . '\', '
. '\'' . DataUtil::formatForStore($file['filedate']) . '\', '
. '\'' . 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
*/
function MediaAttach_searchapi_search_check(&$args)
{
$datarow = &$args['datarow'];
$datarow['url'] = $datarow['extra'];
return true;
}