forked from zikula-modules/Mediashare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnsearchapi.php
95 lines (77 loc) · 2.83 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
<?php
// $Id$
//
// Mediashare by Jorn Wildt (C)
//
require_once 'modules/mediashare/common.php';
/**
* Search plugin info
**/
function mediashare_searchapi_info()
{
$dom = ZLanguage::getModuleDomain('mediashare');
return array('title' => 'mediashare',
'functions' => array(__('Media files', $dom) => 'search'));
}
/**
* Search form component
**/
function mediashare_searchapi_options($args)
{
if (SecurityUtil::checkPermission('mediashare::', '::', ACCESS_READ)) {
$render = pnRender::getInstance('mediashare');
$render->assign('active', !isset($args['active']) && isset($args['active']['mediashare']));
return $render->fetch('mediashare_search_options.html');
}
return '';
}
function mediashare_searchapi_search($args)
{
$dom = ZLanguage::getModuleDomain('mediashare');
pnModDBInfoLoad('mediashare');
pnModDBInfoLoad('Search');
$pntable = pnDBGetTables();
$mediaTable = $pntable['mediashare_media'];
$mediaColumn = $pntable['mediashare_media_column'];
$albumsTable = $pntable['mediashare_albums'];
$albumsColumn = $pntable['mediashare_albums_column'];
$searchTable = $pntable['search_result'];
$searchColumn = $pntable['search_result_column'];
$sessionId = session_id();
// Find accessible albums
$accessibleAlbumSql = pnModAPIFunc('mediashare', 'user', 'getAccessibleAlbumsSql',
array('access' => mediashareAccessRequirementViewSomething,
'field' => "media.$mediaColumn[parentAlbumId]"));
$albumText = __('Multimedia file in album: ', $dom);
$sql = "
INSERT INTO $searchTable
($searchColumn[title],
$searchColumn[text],
$searchColumn[module],
$searchColumn[extra],
$searchColumn[created],
$searchColumn[session])
SELECT CONCAT(media.$mediaColumn[title], ' [$albumText', album.$albumsColumn[title], ']'),
media.$mediaColumn[description],
'mediashare',
CONCAT(album.$albumsColumn[id], ':', media.$mediaColumn[id]),
media.$mediaColumn[createdDate],
'$sessionId'
FROM $mediaTable media
INNER JOIN $albumsTable album
ON album.$albumsColumn[id] = media.$mediaColumn[parentAlbumId]
WHERE ($accessibleAlbumSql) AND ";
$sql .= search_construct_where($args, array("media.$mediaColumn[title]", "media.$mediaColumn[description]", "media.$mediaColumn[keywords]"));
$dbresult = DBUtil::executeSQL($sql);
if (!$dbresult) {
return LogUtil::registerError(__('Error! Could not load items.', $dom));
}
return true;
}
function mediashare_searchapi_search_check(&$args)
{
$datarow = &$args['datarow'];
list ($albumId, $mediaId) = explode(':', $datarow['extra']);
$datarow['url'] = pnModUrl('mediashare', 'user', 'main', array('aid' => $albumId, 'mid' => $mediaId));
return true;
}