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';
29 if (empty($GLOBALS[
'SQ_SYSTEM']->user) || !($GLOBALS[
'SQ_SYSTEM']->user->canAccessBackend() || $GLOBALS[
'SQ_SYSTEM']->user->type() ==
'simple_edit_user')){
34 $quick_search_for_text = translate(
'asset_search_default_keyword');
36 $quick_search_for_text = translate(
'asset_search_default');
39 $search_for = trim(array_get_index($_GET,
'quick-search-for',
''));
42 if ($search_for !=
'') {
44 $asset_by_url = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL(
'', strip_url($search_for, TRUE), TRUE, TRUE);
45 if (!is_a($asset_by_url,
'image') || !$asset_by_url->readAccess()) {
49 if (assert_valid_assetid($search_for,
'', TRUE, FALSE)) {
50 $asset_by_id = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($search_for,
'', TRUE);
51 if (!is_a($asset_by_id,
'image') || !$asset_by_id->readAccess()) {
57 $found_asset_line =
'';
60 if (!empty($asset_by_url)) {
61 $found_asset =& $asset_by_url;
62 $found_asset_line .=
'<strong>'.
'Matched on URL:'.
'</strong>';
65 if (!empty($asset_by_id)) {
66 $found_asset =& $asset_by_id;
67 $found_asset_line .=
'<strong>'.
'Matched on Asset ID:'.
'</strong>';
70 if (!empty($found_asset)) {
71 $asset_title = $found_asset->attr(
'title');
72 $asset_alt = addslashes($found_asset->attr(
'alt'));
73 $asset_width = $found_asset->attr(
'width');
74 $asset_height = $found_asset->attr(
'height');
75 $asset_name = $found_asset->name;
76 $found_asset_line .=
'<div class="search-result">';
77 $found_asset_line .= get_asset_tag_line($found_asset->id,
'javascript:set_asset_finder_from_search(\''.$found_asset->id.
'\', \
''.htmlspecialchars($asset_title, ENT_QUOTES).
'\', \
'\', \
'0\', \''.$asset_name.
'\', \
''.$asset_alt.
'\', \
''.$asset_width.
'\', \
''.$asset_height.
'\');
');
78 $found_asset_line .= '</div>
';
80 // Only search for images
81 $results = Backend_Search::processSearch($search_for, Array(), Array('image
' => TRUE));
83 if (!empty($results)) {
84 $result_list = Array();
86 foreach ($results as $result_assetid => $result_detail) {
87 $tag_line = get_asset_tag_line($result_assetid);
89 $this_detail = Array();
91 foreach ($result_detail as $result_component_name => $result_component) {
92 foreach ($result_component as $name => $value) {
95 switch ($result_component_name) {
97 $name_detail = 'Asset Contents
';
102 $name_detail = ($result_component_name == 'schema
' ? 'Default
' : '').'Metadata:
';
104 // Find a friendly name for the metadata field, if there
105 // is none then use the standard name of the field itself
106 $attr_values = $GLOBALS['SQ_SYSTEM
']->am->getAttributeValuesByName('friendly_name
', 'metadata_field
', Array($name));
107 if (empty($attr_values)) {
108 $name_detail .= $value['name
'];
110 $name_detail .= $attr_values[$name];
113 $value = $value['value
'];
117 $name_detail = 'Attribute:
'.ucwords(str_replace('_
', ' ', $name));
121 $words = explode(' ', $search_for);
122 $value = strip_tags($value);
124 preg_match_all('/(
'.addslashes(implode('|
', $words)).')/i
', $value, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
126 // We go backwards, because that way we don't invalidate
132 if ($matches[count($matches) - 1][0][1] < strlen($value) - 15) {
133 $value = substr_replace($value,
'...', $matches[count($matches) - 1][0][1] + 15);
136 for ($i = count($matches) - 1; $i > 0; $i--) {
137 $previous_match = $matches[$i - 1][0];
138 $this_match = $matches[$i][0];
140 $prev_pos = $previous_match[1] + strlen($previous_match[0]);
141 $next_pos = $this_match[1];
143 if (($next_pos - $prev_pos) > 30) {
144 $value = substr_replace($value,
'...', $prev_pos + 15, ($next_pos - $prev_pos) - 30);
149 if ($matches[0][0][1] > 15) {
150 $value = substr_replace($value,
'...', 0, $matches[0][0][1] - 15);
154 $value = ellipsisize($value, 120);
156 $value = preg_replace(
'/('.addslashes(implode(
'|', $words)).
')/i',
'<span class="sq-backend-search-results-highlight">$1</span>', $value);
159 $this_detail[] = $name_detail.
'<br/><em>'.str_replace(
"\r",
'', str_replace(
"\n",
'<br/>', $value)).
'</em>';
163 $asset_name = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($result_assetid),
'image', FALSE,
'name');
164 $asset_title = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'title',
'image', Array($result_assetid));
165 $asset_alt = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'alt',
'image', Array($result_assetid));
166 $asset_width = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'width',
'image', Array($result_assetid));
167 $asset_height = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'height',
'image', Array($result_assetid));
169 $result_list[] = Array(
170 'tag_line' => get_asset_tag_line($result_assetid,
'javascript:set_asset_finder_from_search(\''.$result_assetid.
'\', \
''.htmlspecialchars(array_get_index($asset_title, $result_assetid,
''), ENT_QUOTES).
'\', \
'\', \
'0\', \''.array_get_index($asset_name, $result_assetid,
'').
'\', \
''.addslashes(array_get_index($asset_alt, $result_assetid,
'')).
'\', \
''.array_get_index($asset_width, $result_assetid,
'').
'\', \
''.array_get_index($asset_height, $result_assetid,
'').
'\');
'),
171 'detail
' => implode($this_detail, '<br/>
'),
177 // Are there any results? If not, put in a "search failed" box, otherwise
178 // build the results box
179 if (empty($results) && empty($found_asset_line)) {
180 $box_title = translate('search_failed
');
181 $html = translate('failed_searching_for
', addslashes($search_for));
182 $style_base = 'search-failed
';
184 $box_title = translate('search_results
');
186 if (!empty($found_asset_line)) {
187 $html .= '<div
class=
"search-result">
'.$found_asset_line.'</div>
';
190 if (count($results) > 0) {
193 $results_per_page = $GLOBALS['SQ_SYSTEM
']->getUserPrefs('search_manager
', 'SQ_SEARCH_BACKEND_PAGE_SIZE
');
194 $total_pages = ceil(count($results) / $results_per_page);
196 $html .= '<div
class=
"search-result-blurb">Matched on Keyword (
'.count($results).' asset
'.(count($results) == 1 ? '' : 's
').'):</div>
';
198 if ($total_pages > 1) {
199 $html .= '<div class=
"search-result-pager">
200 <a href=
"" onclick=
"jump_to_search_results(1); return false;" title=
"Go back to first page"><<</a>
201 <a href=
"" onclick=
"jump_to_search_results(Math.max(current - 1, 1)); return false;" title=
"Go back one page"><</a>
202 <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>
203 <a href=
"" onclick=
"jump_to_search_results(Math.min(current + 1, '.$total_pages.')); return false;" title=
"Go forward one page">></a>
204 <a href=
"" onclick=
"jump_to_search_results('.$total_pages.'); return false;" title=
"Go forward to last page">>></a>
208 foreach ($result_list as $this_result) {
209 $page_number = floor($result_number / $results_per_page) + 1;
211 // Start of a new page
212 if ($result_number % $results_per_page == 0) {
213 if ($page_number > 1) $html .= '</div>
';
214 $html .= '<div
class=
"search-result-page" id=
"search-result-page-'.$page_number.'"';
215 if ($page_number > 1) {
216 $html .= ' style=
"display: none"';
223 $html .= '<div
class=
"search-result" id=
"search-result-'.$result_number.'">
';
224 $html .= '<div
class=
"search-result-expand-div" id=
"search-result-'.$result_number.'-expand-div">
';
225 $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>
';
227 $html .= '<div
class=
"search-result-entry" id=
"search-result-'.$result_number.'-entry">
'.$this_result['tag_line
'].'</div>
';
228 $html .= '<div
class=
"search-result-detail" id=
"search-result-'.$result_number.'-detail">
'.$this_result['detail
'].'</div>
';
237 $style_base = 'search-results
';
240 $html = str_replace("\r", '', $html);
241 $html = str_replace("\n", ' ', $html);
243 }//end if - we are searching for something
248 <title>Insert Link - Search</title>
249 <style type="text/css">
253 font: 11px Tahoma,Verdana,sans-serif;
264 font: 11px Arial,Verdana,sans-serif;
265 border: 1px solid black;
269 #quick-search-for-label {
270 font: 11px Arial,Verdana,sans-serif;
274 /* main popup title */
280 border-bottom: 1px solid black;
285 /* form and form fields */
286 form { padding: 0px; margin: 0px; }
288 <script type="text/javascript"><!--
297 function quick_search_for_onfocus(field)
299 if (field.value == '<?php echo addslashes($quick_search_for_text) ?>
') {
318 function quick_search_for_onblur(field)
320 if (field.value == '') {
321 field.value = '<?php echo addslashes($quick_search_for_text) ?>
';
336 function quick_search_onsubmit(form)
338 if ((form.elements['quick-search-
for'].value == '') || (form.elements['quick-search-
for'].value == '<?php echo addslashes($quick_search_for_text) ?>
')) {
342 top.frames['sq_wysiwyg_popup_main
'].document.getElementById('search-wait-popup
').style.display = 'block
';
343 top.frames['sq_wysiwyg_popup_main
'].document.getElementById('new-message-popup
').style.display = 'none
';
348 // If something was being searched for, fill and show the search results
349 if ($search_for != '') {
354 // Reset variables in the main frame
355 top.frames['sq_wysiwyg_popup_main
'].total_results = <?php echo count($results); ?>;
356 top.frames['sq_wysiwyg_popup_main
'].current = 1;
358 function show_search_results()
360 top.frames['sq_wysiwyg_popup_main
'].document.getElementById('search-wait-popup
').style.display = 'none
';
362 var results_box = top.frames['sq_wysiwyg_popup_main
'].document.getElementById('new-message-popup
');
363 var results_box_text = top.frames['sq_wysiwyg_popup_main
'].document.getElementById('new-message-popup-details
');
364 var results_box_title = top.frames['sq_wysiwyg_popup_main
'].document.getElementById('new-message-popup-title
');
365 var results_box_titlebar = top.frames['sq_wysiwyg_popup_main
'].document.getElementById('new-message-popup-titlebar
');
367 var html = '<?php echo addslashes($html) ?>
';
368 var title_html = '<?php echo addslashes($box_title) ?>
';
369 var class_name = '<?php echo addslashes($style_base) ?>
';
371 results_box.className = 'sq-backend-
' + class_name + '-table
';
372 results_box_titlebar.className = 'sq-backend-
' + class_name + '-heading
';
373 results_box_text.className = 'sq-backend-
' + class_name + '-body
';
375 results_box.style.visibility = 'hidden
';
377 results_box_title.innerHTML = title_html;
378 results_box_text.innerHTML = html;
379 results_box.style.display = 'block
';
381 height = results_box.offsetHeight;
383 results_box.style.top = -counter + 'px
';
385 results_box.style.visibility = 'visible
';
387 interval = setInterval('move_search_results();
', 30);
390 function move_search_results()
392 move = Math.max(Math.min(Math.abs(counter) * 0.08, 10), 2);
395 var results_box = top.frames['sq_wysiwyg_popup_main
'].document.getElementById('new-message-popup
');
396 results_box.style.top = -counter + 'px
';
399 clearTimeout(interval);
403 }//end if - something was being searched for
408 <body<?php if ($search_for != '') {
410 onload="show_search_results();"
417 <div class="title"><form action="" method="get" id="quick-search" onsubmit="return quick_search_onsubmit(this);">
418 <label id="quick-search-for-label" for="quick-search-for">Quick Search for Images</label>
419 <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);">