-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcivisearch.php
executable file
·185 lines (154 loc) · 5.92 KB
/
civisearch.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* @version
* @package Civicrm
* @subpackage Joomla Plugin
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// no direct access
defined('_JEXEC') or die;
if(version_compare(JVERSION,'1.6.0','ge')) {
jimport('joomla.plugin.plugin');
require_once JPATH_SITE.'/components/com_content/router.php';
} else {
$mainframe->registerEvent( 'onSearch', 'plgSearchCiviSearch' );
$mainframe->registerEvent( 'onSearchAreas', 'plgSearchCiviSearchAreas' );
JPlugin::loadLanguage( 'plg_search_civisearch' );
}
/**
* CiviCRM Search plugin
*
* @package Joomla.Plugin
* @subpackage Search.content
* @since 1.5
*/
function &plgSearchCiviSearchAreas()
{
static $areas = array(
'events' => 'Events'
);
return $areas;
}
function plgSearchCiviSearch( $text, $phrase='', $ordering='', $areas=null )
{
$return = plgSearchCiviSearch::onContentSearch($text, $phrase='', $ordering='', $areas=null);
return $return;
}
class plgSearchCiviSearch extends JPlugin
{
/**
* @return array An array of search areas
*/
function onContentSearchAreas()
{
$areas = plgSearchCiviSearchAreas();
return $areas;
}
/**
* Search method
* The sql must return the following fields that are used in a common display
* routine: href, title, section, created, text, browsernav
* @param string Target search string
* @param string mathcing option, exact|any|all
* @param string ordering option, newest|oldest|popular|alpha|category
* @param mixed An array if the search it to be restricted to areas, null if search all
*/
function onContentSearch($text, $phrase='', $ordering='', $areas=null)
{
if(version_compare(JVERSION,'1.6.0','ge')) {
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$tag = JFactory::getLanguage()->getTag();
require_once JPATH_SITE.'/components/com_content/helpers/route.php';
require_once JPATH_SITE.'/administrator/components/com_search/helpers/search.php';
$searchText = $text;
if (is_array($areas)) {
if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
return array();
}
}
$sEvent = $this->params->get('search_event');
$limit = $this->params->def('search_limit', 50);
$itemid = $this->params->def('itemid');
} else {
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$searchText = $text;
require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
if (is_array( $areas )) {
if (!array_intersect( $areas, array_keys( plgSearchCategoryAreas() ) )) {
return array();
}
}
// load plugin params info
$plugin =& JPluginHelper::getPlugin('search', 'civisearch');
$pluginParams = new JParameter( $plugin->params );
$limit = $pluginParams->def( 'search_limit', 50 );
$itemid = $pluginParams->def('itemid');
}
$text = trim( $text );
if ( $text == '' ) {
return array();
}
switch ( $ordering ) {
case 'alpha':
$order = 'a.title ASC';
break;
case 'newest':
$order = 'a.start_date DESC';
break;
case 'oldest':
$order = 'a.start_date ASC';
break;
default:
$order = 'a.id DESC';
}
$text = $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false );
$select = 'a.title, a.description AS text, a.created_date AS created, a.summary AS summary, a.id AS eventid';
$from = 'civicrm_event AS a';
$where = '(a.title LIKE '. $text .' OR a.description LIKE '. $text .' OR a.summary LIKE '. $text .') AND a.is_public = 1 AND a.is_template = 0 AND a.is_active = 1';
$group = 'a.id';
$return = array();
if(version_compare(JVERSION,'1.6.0','ge')) {
$query = $db->getQuery(true);
$query->select($select);
$query->from($from);
$query->where($where);
$query->group($group);
$query->order($order);
if ($app->isSite() && $app->getLanguageFilter()) {
$query->where('a.language in (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ')');
}
} else {
$query = 'SELECT '.$select
. ' FROM '.$from
. ' WHERE '.$where
. ' GROUP BY '.$group
. ' ORDER BY '. $order
;
}
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$itemid_url = '';
if (isset($itemid)) {
$itemid_url = '&Itemid='.$itemid;
}
if ($rows) {
$count = count($rows);
for ($i = 0; $i < $count; $i++) {
$rows[$i]->href = 'index.php?option=com_civicrm&task=civicrm/event/info&reset=1&id='.$rows[$i]->eventid.$itemid_url;
$rows[$i]->section = JText::_('Event');
}
$return = array();
foreach($rows AS $key => $event) {
if (searchHelper::checkNoHTML($event, $searchText, array('summary', 'title', 'text'))) {
$return[] = $event;
}
}
}
return $return;
}
}