25 require_once dirname(__FILE__).
'/../../../../core/include/init.inc';
26 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
27 require_once SQ_LIB_PATH.
'/backend_search/backend_search.inc';
28 require_once SQ_FUDGE_PATH.
'/general/general.inc';
30 if (empty($GLOBALS[
'SQ_SYSTEM']->user) || !($GLOBALS[
'SQ_SYSTEM']->user->canAccessBackend() || $GLOBALS[
'SQ_SYSTEM']->user->type() ==
'simple_edit_user')){
35 $quick_search_for_text = translate(
'asset_search_default_keyword');
37 $quick_search_for_text = translate(
'asset_search_default');
40 $search_for = trim(array_get_index($_GET,
'quick-search-for',
''));
43 if ($search_for !=
'') {
45 $asset_by_url = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL(
'', strip_url($search_for, TRUE), TRUE, TRUE);
46 if (assert_valid_assetid($search_for,
'', TRUE, FALSE)) {
47 $asset_by_id = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($search_for,
'', TRUE);
51 $found_asset_line =
'';
54 if (!empty($asset_by_url)) {
55 $found_asset =& $asset_by_url;
56 $found_asset_line .=
'<strong>'.
'Matched on URL:'.
'</strong>';
59 if (!empty($asset_by_id)) {
60 $found_asset =& $asset_by_id;
61 $found_asset_line .=
'<strong>'.
'Matched on Asset ID:'.
'</strong>';
65 if (!empty($found_asset) && !$found_asset->readAccess()) {
67 $found_asset_line =
'';
70 if (!empty($found_asset)) {
71 $asset_name = $found_asset->name;
72 $found_asset_line .=
'<div class="search-result">';
73 $found_asset_line .= get_asset_tag_line($found_asset->id,
'javascript:set_asset_finder_from_search(\''.$found_asset->id.
'\', \
''.htmlspecialchars($asset_name, ENT_QUOTES).
'\', \
'\', \
'0\')');
74 $found_asset_line .=
'</div>';
79 if (!empty($results)) {
80 $result_list = Array();
82 foreach ($results as $result_assetid => $result_detail) {
83 $tag_line = get_asset_tag_line($result_assetid);
85 $this_detail = Array();
87 foreach ($result_detail as $result_component_name => $result_component) {
88 foreach ($result_component as $name => $value) {
91 switch ($result_component_name) {
93 $name_detail =
'Asset Contents';
98 $name_detail = ($result_component_name ==
'schema' ?
'Default ' :
'').
'Metadata: ';
102 $attr_values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'friendly_name',
'metadata_field', Array($name));
103 if (empty($attr_values)) {
104 $name_detail .= $value[
'name'];
106 $name_detail .= $attr_values[$name];
109 $value = $value[
'value'];
113 $name_detail =
'Attribute: '.ucwords(str_replace(
'_',
' ', $name));
117 $words = explode(
' ', $search_for);
118 $value = strip_tags($value);
120 preg_match_all(
'/('.addslashes(implode(
'|', $words)).
')/i', $value, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
128 if ($matches[count($matches) - 1][0][1] < strlen($value) - 15) {
129 $value = substr_replace($value,
'...', $matches[count($matches) - 1][0][1] + 15);
132 for ($i = count($matches) - 1; $i > 0; $i--) {
133 $previous_match = $matches[$i - 1][0];
134 $this_match = $matches[$i][0];
136 $prev_pos = $previous_match[1] + strlen($previous_match[0]);
137 $next_pos = $this_match[1];
139 if (($next_pos - $prev_pos) > 30) {
140 $value = substr_replace($value,
'...', $prev_pos + 15, ($next_pos - $prev_pos) - 30);
145 if ($matches[0][0][1] > 15) {
146 $value = substr_replace($value,
'...', 0, $matches[0][0][1] - 15);
150 $value = ellipsisize($value, 120);
152 $value = preg_replace(
'/('.addslashes(implode(
'|', $words)).
')/i',
'<span class="sq-backend-search-results-highlight">$1</span>', $value);
155 $this_detail[] = $name_detail.
'<br/><em>'.str_replace(
"\r",
'', str_replace(
"\n",
'<br/>', $value)).
'</em>';
159 $asset_name = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($result_assetid,
'asset', FALSE,
'name');
161 $result_list[] = Array(
162 'tag_line' => get_asset_tag_line($result_assetid,
'javascript:set_asset_finder_from_search(\''.$result_assetid.
'\', \
''.htmlspecialchars($asset_name[$result_assetid], ENT_QUOTES).
'\', \
'\', \
'0\');'),
163 'detail' => implode($this_detail,
'<br/>'),
171 if (empty($results) && empty($found_asset_line)) {
172 $box_title = translate(
'search_failed');
173 $html = translate(
'failed_searching_for', addslashes($search_for));
174 $style_base =
'search-failed';
176 $box_title = translate(
'search_results');
178 if (!empty($found_asset_line)) {
179 $html .=
'<div class="search-result">'.$found_asset_line.
'</div>';
182 if (count($results) > 0) {
185 $results_per_page = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'search_manager',
'SQ_SEARCH_BACKEND_PAGE_SIZE');
186 $total_pages = ceil(count($results) / $results_per_page);
188 $html .=
'<div class="search-result-blurb">Matched on Keyword ('.count($results).
' asset'.(count($results) == 1 ?
'' :
's').
'):</div>';
190 if ($total_pages > 1) {
191 $html .=
'<div class="search-result-pager">
192 <a href="" onclick="jump_to_search_results(1); return false;" title="Go back to first page"><<</a>
193 <a href="" onclick="jump_to_search_results(Math.max(current - 1, 1)); return false;" title="Go back one page"><</a>
194 <strong>( <span id="sq-search-results-page-start">1</span> - <span id="sq-search-results-page-end">'.min(count($results), $results_per_page).
'</span> )</strong>
195 <a href="" onclick="jump_to_search_results(Math.min(current + 1, '.$total_pages.
')); return false;" title="Go forward one page">></a>
196 <a href="" onclick="jump_to_search_results('.$total_pages.
'); return false;" title="Go forward to last page">>></a>
200 foreach ($result_list as $this_result) {
201 $page_number = floor($result_number / $results_per_page) + 1;
204 if ($result_number % $results_per_page == 0) {
205 if ($page_number > 1) $html .=
'</div>';
206 $html .=
'<div class="search-result-page" id="search-result-page-'.$page_number.
'"';
207 if ($page_number > 1) {
208 $html .=
' style="display: none"';
215 $html .=
'<div class="search-result" id="search-result-'.$result_number.
'">';
216 $html .=
'<div class="search-result-expand-div" id="search-result-'.$result_number.
'-expand-div">';
217 $html .=
'<a href="#" id="search-result-'.$result_number.
'-expand-link" class="search-result-expand-link" onclick="if (this.innerHTML == \'+\') {document.getElementById(\'search-result-'.$result_number.
'-detail\').style.display = \'block\'; this.innerHTML = \'-\';} else {document.getElementById(\'search-result-'.$result_number.
'-detail\').style.display = \'none\'; this.innerHTML = \'+\';} return false;">+</a>';
219 $html .=
'<div class="search-result-entry" id="search-result-'.$result_number.
'-entry">'.$this_result[
'tag_line'].
'</div>';
220 $html .=
'<div class="search-result-detail" id="search-result-'.$result_number.
'-detail">'.$this_result[
'detail'].
'</div>';
229 $style_base =
'search-results';
232 $html = str_replace(
"\r",
'', $html);
233 $html = str_replace(
"\n",
' ', $html);
240 <title>Insert
Link - Search</title>
241 <style type=
"text/css">
245 font: 11px Tahoma,Verdana,sans-serif;
256 font: 11px Arial,Verdana,sans-serif;
257 border: 1px solid black;
261 #quick-search-for-label {
262 font: 11px Arial,Verdana,sans-serif;
272 border-bottom: 1px solid black;
278 form { padding: 0px; margin: 0px; }
280 <script type=
"text/javascript"><!--
289 function quick_search_for_onfocus(field)
291 if (field.value ==
'<?php echo addslashes($quick_search_for_text) ?>') {
310 function quick_search_for_onblur(field)
312 if (field.value ==
'') {
313 field.value =
'<?php echo addslashes($quick_search_for_text) ?>';
328 function quick_search_onsubmit(form)
330 if ((form.elements[
'quick-search-for'].value ==
'') || (form.elements[
'quick-search-for'].value ==
'<?php echo addslashes($quick_search_for_text) ?>')) {
334 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'search-wait-popup').style.display =
'block';
335 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'new-message-popup').style.display =
'none';
341 if ($search_for !=
'') {
347 top.frames[
'sq_wysiwyg_popup_main'].total_results = <?php echo count($results); ?>;
348 top.frames[
'sq_wysiwyg_popup_main'].current = 1;
350 function show_search_results()
352 top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'search-wait-popup').style.display =
'none';
354 var results_box = top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'new-message-popup');
355 var results_box_text = top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'new-message-popup-details');
356 var results_box_title = top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'new-message-popup-title');
357 var results_box_titlebar = top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'new-message-popup-titlebar');
359 var html =
'<?php echo addslashes($html) ?>';
360 var title_html =
'<?php echo addslashes($box_title) ?>';
361 var class_name =
'<?php echo addslashes($style_base) ?>';
363 results_box.className =
'sq-backend-' + class_name +
'-table';
364 results_box_titlebar.className =
'sq-backend-' + class_name +
'-heading';
365 results_box_text.className =
'sq-backend-' + class_name +
'-body';
367 results_box.style.visibility =
'hidden';
369 results_box_title.innerHTML = title_html;
370 results_box_text.innerHTML = html;
371 results_box.style.display =
'block';
373 height = results_box.offsetHeight;
375 results_box.style.top = -counter +
'px';
377 results_box.style.visibility =
'visible';
379 interval = setInterval(
'move_search_results();', 30);
382 function move_search_results()
384 move = Math.max(Math.min(Math.abs(counter) * 0.08, 10), 2);
387 var results_box = top.frames[
'sq_wysiwyg_popup_main'].document.getElementById(
'new-message-popup');
388 results_box.style.top = -counter +
'px';
391 clearTimeout(interval);
400 <body<?php
if ($search_for !=
'') {
402 onload=
"show_search_results();"
409 <div
class=
"title"><form action=
"" method=
"get" id=
"quick-search" onsubmit=
"return quick_search_onsubmit(this);">
410 <label
id=
"quick-search-for-label" for=
"quick-search-for">Quick Search</label>
411 <input type=
"text" size=
"30" value=
"<?php echo htmlspecialchars(empty($search_for) ? $quick_search_for_text : $search_for); ?>" name=
"quick-search-for" id=
"quick-search-for" onfocus=
"return quick_search_for_onfocus(this);" onblur=
"return quick_search_for_onblur(this);" onkeypress=
"if (event.keyCode == 13) return quick_search_onsubmit(this.form);">