-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpnsearchapi.php
More file actions
128 lines (112 loc) · 4.1 KB
/
Copy pathpnsearchapi.php
File metadata and controls
128 lines (112 loc) · 4.1 KB
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
121
122
123
124
125
126
127
<?php
/**
* Zikula Application Framework
*
* @copyright (c) 2001, Zikula Development Team
* @link http://www.zikula.org
* @version $Id$
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package Zikula_System_Modules
* @subpackage Users
*/
/**
* Search plugin info
**/
function Admin_Messages_searchapi_info()
{
return array('title' =>'Admin_Messages',
'functions' => array('Admin_Messages' => 'search'));
}
/**
* Search form component
**/
function Admin_Messages_searchapi_options($args)
{
if (SecurityUtil::checkPermission('Admin_Messages:search:', '::', ACCESS_READ)) {
// Create output object
$view = Zikula_View::getInstance('Admin_Messages');
$view->assign(ModUtil::getVar('Admin_Messages'));
$view->assign('active', (isset($args['active']) && isset($args['active']['Admin_Messages'])) || (!isset($args['active'])));
$view->assign('activeonly', (isset($args['modvar']) && isset($args['modvar']['Admin_Messages']) && isset($args['modvar']['Admin_Messages']['activeonly']))||!isset($args['modvar']));
return $view->fetch('admin_messages_search_options.htm');
}
return '';
}
/**
* Get all admin messages items that match the criteria
*
* @author Mark West, Jorn Wildt
* @param bool args['activeonly'] only show active items
* @return bool true/false on success/failure
*/
function Admin_Messages_searchapi_search($args)
{
$dom = ZLanguage::getModuleDomain('Admin_Messages');
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_READ)) {
return true;
}
// get the db and table info
ModUtil::dbInfoLoad('Search');
$pntable = DBUtil::getTables();
$messagestable = $pntable['message'];
$messagescolumn = $pntable['message_column'];
$searchTable = &$pntable['search_result'];
$searchColumn = &$pntable['search_result_column'];
// form the where clause
$where = '';
if (!ModUtil::getVar('Admin_Messages', 'allowsearchinactive') || (isset($args['activeonly']) && (bool)$args['activeonly'])){
$where .= " $messagescolumn[active] = 1 AND ";
}
$where .= " ($messagescolumn[date]+$messagescolumn[expire] > '".time()."' OR $messagescolumn[expire] = 0) AND";
$where .= search_construct_where($args, array($messagescolumn['title'], $messagescolumn['content']), $messagescolumn['language']);
$sessionId = session_id();
$sql = "
SELECT
$messagescolumn[mid] as mid,
$messagescolumn[title] as title,
$messagescolumn[content] as text,
$messagescolumn[date] as date
FROM $messagestable
WHERE $where";
$result = DBUtil::executeSQL($sql);
if (!$result) {
return LogUtil::registerError(__('Error! Could not load data.'));
}
$insertSql =
"INSERT INTO $searchTable
($searchColumn[title],
$searchColumn[text],
$searchColumn[module],
$searchColumn[created],
$searchColumn[session])
VALUES ";
// Process the result set and insert into search result table
for (; !$result->EOF; $result->MoveNext()) {
$message = $result->GetRowAssoc(2);
if (SecurityUtil::checkPermission('Admin_Messages::', "$message[title]::$message[mid]", ACCESS_READ)) {
$sql = $insertSql . '('
. '\'' . DataUtil::formatForStore($message['title']) . '\', '
. '\'' . DataUtil::formatForStore($message['text']) . '\', '
. '\'' . 'Admin_Messages' . '\', '
. '\'' . DataUtil::formatForStore(DateUtil::getDatetime($message['date'])) . '\', '
. '\'' . DataUtil::formatForStore($sessionId) . '\')';
$insertResult = DBUtil::executeSQL($sql);
if (!$insertResult) {
return LogUtil::registerError(__('Error! Could not load data.', $dom));
}
}
}
return true;
}
/**
* Do last minute access checking and assign URL to items
*
* Both access checking and URL creation is ignored: access check has
* already been done and there's no URL to the admin messages.
*/
function Admin_Messages_searchapi_search_check(&$args)
{
// True = has access
return true;
}