17 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
18 require_once SQ_FUDGE_PATH.
'/general/text.inc';
19 require_once SQ_FUDGE_PATH.
'/general/general.inc';
20 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
21 require_once SQ_PACKAGES_PATH.
'/cms/listing_engine/listing_engine.inc';
22 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
23 require_once SQ_FUDGE_PATH.
'/datetime_field/datetime_field.inc';
44 var $bodycopies = Array(
45 'initial' =>
'Initial Search Page Layout',
46 'results' =>
'Results Page Layout',
47 'no_results' =>
'No Results Page Layout',
55 var $defaults = Array (
'query_width' => 25);
62 var $keywords = Array(
66 'structured_root_node',
71 'current_result_page',
74 'previous_result_page_link',
75 'next_result_page_link',
76 'previous_result_page_href',
77 'next_result_page_href',
79 'category_list_linked',
80 'structured_root_node',
81 'initial_result_count',
83 'no_results' => Array(
97 $this->_ser_attrs = TRUE;
98 parent::__construct($assetid);
125 if (!parent::_createAdditional($link))
return FALSE;
128 if (!$lock_held = $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->id,
'attributes')) {
136 if ($lock_held == 1) {
137 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->
id,
'attributes');
155 foreach ($this->bodycopies as $value => $name) {
158 'link_type' => SQ_LINK_TYPE_2,
165 $bodycopy->setAttrValue(
'name', $name);
167 if (!$bodycopy->create($copy_link, $args)) {
187 switch ($bodycopy_code) {
189 return '<p>'.translate(
'sch_page_search_for').
'</p><p>%submit_button%</p>';
191 return '<p>'.translate(
'sch_page_x_results_found',
'%result_count%').
'</p>%result_list%';
193 return '<p>'.translate(
'sch_page_no_results_try_again').
'</p>%initial_layout%';
195 return parent::_getDefaultBodycopyContent($bodycopy_code);
220 function prepareLink(&$asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
223 if ($side_of_link ==
'major' && ($asset instanceof
Bodycopy) && $dependant !=
'1') {
245 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
247 if ($bodycopy_link[
'minor_type_code'] ==
'bodycopy' && in_array($bodycopy_link[
'value'], $this->bodycopies) && !$GLOBALS[
'SQ_PURGING_TRASH']) {
248 return translate(
'sch_page_cannot_delete_bodycopies');
251 return parent::isDeletableLink($linkid);
265 $page_links = parent::_getAllowedLinks();
266 $page_links[SQ_LINK_TYPE_2][
'bodycopy'] = Array(
'card' =>
'M',
'exclusive' => TRUE);
267 $page_links[SQ_LINK_TYPE_2][
'folder'] = Array(
'card' => 4,
'exclusive' => FALSE);
268 $page_links[SQ_LINK_TYPE_3][
'folder'] = Array(
'card' => 1,
'exclusive' => FALSE);
269 $page_links[SQ_LINK_NOTICE][
'asset'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
285 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
286 switch (strtolower($link[
'value'])) {
288 return translate(
'sch_page_root_node_link_desc');
291 return parent::describeLink($linkid);
307 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'prepareSearchQuery');
309 if (isset($_REQUEST[$this->
getPrefix().
'_submit_button']) && empty($_REQUEST[
'mode'])) {
310 $_REQUEST[
'mode'] =
'results';
313 $mode = array_get_index($_REQUEST,
'mode',
'');
320 foreach ($queries as $field_name => $value) {
321 if (!empty($value)) {
325 unset($queries[$field_name]);
329 $this->_tmp[
'searched_queries'] = $queries;
332 if (empty($_SESSION[
'SQ_LAST_SEARCH'][$this->
id])) {
333 $_SESSION[
'SQ_LAST_SEARCH'][$this->id] = Array();
342 $this->_tmp[
'potential_searched_queries'] = $_SESSION[
'SQ_LAST_SEARCH'][$this->id];
346 $_SESSION[
'SQ_LAST_SEARCH'][$this->id] = Array();
351 if (empty($mode)) $mode =
'initial';
354 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
356 $listing_result_page = (int) array_get_index($_REQUEST,
'result_'.$this->
id.
'_result_page', 0);
357 $search_result_page = (int) array_get_index($_REQUEST,
'current_result_page', 1);
358 if ($listing_result_page === 0) {
359 $current_result_page = $search_result_page;
361 $current_result_page = $listing_result_page;
363 $results_per_page = (int) array_get_index($_REQUEST,
'results_per_page', $this->
_getNumPerPage());
364 $submitted_category = htmlentities(array_get_index($_REQUEST,
'search_category', array_get_index($_REQUEST,
'submitted_search_category')));
366 if (empty($_REQUEST[
'search_category']) && !empty($submitted_category)) {
367 $_REQUEST[
'search_category'] = $submitted_category;
374 if ($this->
attr(
'stored_query_show_results') && $mode ==
'initial' && $this->_tmp[
'jump_to_result']) {
379 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'prepareSearchQuery');
382 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'printBody');
397 if (!empty($this->_tmp[
'prints_submit'])) {
400 <input
type=
"hidden" name=
"current_result_page" value=
"<?php echo $current_result_page; ?>" />
401 <input type=
"hidden" name=
"results_per_page" value=
"<?php echo $results_per_page; ?>" />
408 <input type=
"hidden" name=
"submitted_search_category" value=
"<?php echo $submitted_category; ?>" />
409 <input type=
"hidden" name=
"mode" value=
"" />
417 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'printBody');
434 if ($this->
attr(
'exclude_self')) {
436 foreach ($root_nodes as $exclude_assetid) {
437 if (isset($results[$exclude_assetid])) {
438 unset($results[$exclude_assetid]);
443 if($this->
attr(
'exclude_current_asset')) {
444 foreach ($results as $assetid => $data) {
445 $url = strip_url($GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($assetid));
446 $requester = strip_url(current_url());
447 if ($requester === $url) {
448 unset($results[$assetid]);
453 $this->_tmp[
'initial_results'] = $results;
455 $this->_tmp[
'search_results'] =& $results;
456 $bc_name =
'results';
457 if (empty($results)) $bc_name =
'no_results';
460 $keywords = $bodycopy->getKeywords();
466 if (!in_array(
'select_all_js_code', $keywords)) {
506 if (count($asset_list) == 1 || empty($sort_info)) {
510 if ((!isset($sort_info[
'type']) || ($sort_info[
'type'] ==
'')) && (!isset($sort_info[
'params'][
'field']) || $sort_info[
'params'][
'field'] ==
'')) {
511 if (!empty($asset_list)) arsort($asset_list);
515 if (isset($sort_info[
'params'][
'field'])) {
519 if ($sort_info[
'params'][
'field'] ==
'score') {
530 return parent::sortAssetList($asset_list, $sort_info);
550 if (array_key_exists($name, $this->bodycopies)) {
551 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
552 $link = $am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $name,
'major',
'1');
553 $bodycopy = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
575 if (is_null($bodycopy))
return '';
577 $bodycopy->setKeywordReplacements($replacements);
580 $bodycopy->printBody();
581 $html = ob_get_contents();
604 $mixed_ds_types = FALSE;
605 if (count($field[
'data_sources']) > 1) {
607 $first_ds_type = NULL;
608 $first_field_type = NULL;
609 foreach ($field[
'data_sources'] as $ds) {
610 if (is_null($first_ds_type)) {
611 $first_ds_type = $ds[
'type'];
613 if ($ds[
'type'] != $first_ds_type) {
614 $mixed_ds_types = TRUE;
617 $this_field_type = NULL;
618 switch ($ds[
'type']) {
620 $assetid = $ds[
'params'][
'assetid'];
621 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
622 if (!is_null($asset)) {
623 $this_field_type = get_class_lower($asset);
627 $attribute = $GLOBALS[
'SQ_SYSTEM']->am->getAttribute($ds[
'params'][
'attrid']);
628 $this_field_type = $attribute->type();
631 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager');
632 if (isset($sm->standard_date_fields[$ds[
'params'][
'field']])) {
633 $this_field_type =
'date';
635 $this_field_type =
'text';
639 if (is_null($first_field_type)) {
640 $first_field_type = $this_field_type;
642 if ($this_field_type != $first_field_type) {
643 $mixed_ds_types = TRUE;
646 if (in_array(strtolower($this_field_type), Array(
'selection',
'metadata_field_select',
'metadata_field_hierarchy'))) {
647 $mixed_ds_types = TRUE;
652 return $mixed_ds_types;
668 'min' =>
'0000-01-01 00:00:00',
669 'max' =>
'9999-12-31 23:59:59',
670 'allow_circa' =>
'0',
671 'print_format' =>
'',
672 'show' => Array(
'y',
'm',
'd'),
673 'null' => Array(
'y',
'm',
'd'),
681 $value =
'---------- --:--:--';
682 $field =
new DateTime_Field($field_name, $value, $parameters, TRUE);
698 if (!isset($current_value[
'from'])) {
699 $current_value[
'from'] =
'---------- --:--:--';
702 if (!isset($current_value[
'to'])) {
703 $current_value[
'to'] =
'---------- --:--:--';
707 if ($current_value[
'from'] !=
'---------- --:--:--') {
708 $from = iso8601_ts($current_value[
'from']);
709 $from_string = date(
'j M Y', $from);
713 if ($current_value[
'to'] !=
'---------- --:--:--') {
714 $to = iso8601_ts($current_value[
'to']);
715 $to_string = date(
'j M Y', $to);
718 if (empty($from_string) && empty($to_string)) {
720 }
else if (empty($from_string)) {
721 echo translate(
'sch_page_date_range_prior_to', $to_string);
722 }
else if (empty($to_string)) {
723 echo translate(
'sch_page_date_range_onwards', $from_string);
724 }
else if ($from_string == $to_string) {
727 echo $from_string.
' - '.$to_string;
745 if (!isset($current_value[
'from'])) {
746 $current_value[
'from'] =
'---------- --:--:--';
749 if (!isset($current_value[
'to'])) {
750 $current_value[
'to'] =
'---------- --:--:--';
753 if ($this->
attr(
'use_picker')) {
754 require_once SQ_LIB_PATH.
'/js_calendar/js_calendar.inc';
756 ?><script src=
"<?php echo sq_web_path('lib'); ?>/html_form/html_form.js"
757 type=
"text/javascript"></script><?php
762 <table border=
"0" cellspacing=
"0" cellpadding=
"0">
764 <td align=
"right"><?php echo ucfirst(translate(
'from')) ?>:</td>
767 if ($read_only && $current_value[
'from'] !=
'---------- --:--:--') {
768 $from = iso8601_ts($current_value[
'from']);
769 echo date(
'j M Y', $from);
772 if (!$field->processField() || $field->value ==
'---------- --:--:--') {
773 $field->setValue($current_value[
'from']);
775 $field->printField();
780 if ($this->
attr(
'use_picker') && (!$read_only || $current_value[
'from'] ==
'---------- --:--:--')) {
787 $calendar->changeSetting(
'onDayClick',
'datetime_set_date');
788 $calendar->paint($field_name.
'_from',
'', TRUE);
796 <td align=
"right"><?php echo ucfirst(translate(
'to')) ?>:</td>
799 if ($read_only && $current_value[
'to'] !=
'---------- --:--:--') {
800 $to = iso8601_ts($current_value[
'to']);
801 echo date(
'j M Y', $to);
804 if (!$field->processField() || $field->value ==
'---------- --:--:--') {
805 $field->setValue($current_value[
'to']);
807 $field->printField();
812 if ($this->
attr(
'use_picker') && (!$read_only || $current_value[
'to'] ==
'---------- --:--:--')) {
819 $calendar->changeSetting(
'onDayClick',
'datetime_set_date');
820 $calendar->paint($field_name.
'_to',
'', TRUE);
846 if ($field->processField()) {
847 $result[
'from'] = $field->value;
851 if ($field->processField()) {
852 $result[
'to'] = $field->value;
873 switch (array_get_index($params,
'numeric_search',
'exact')) {
875 if ($sub_field ==
'') print $current_value[
'lower'];
879 if (!isset($current_value[
'upper'])) {
880 $current_value[
'upper'] = NULL;
883 if (!isset($current_value[
'lower'])) {
884 $current_value[
'lower'] = NULL;
887 if ($sub_field ==
'lower') {
888 print array_get_index($current_value,
'lower',
'');
889 }
else if ($sub_field ==
'upper') {
890 print array_get_index($current_value,
'upper',
'');
892 if (is_null($current_value[
'lower'])) {
893 echo
'<= '.$current_value[
'upper'];
894 }
else if (is_null($current_value[
'upper'])) {
895 echo
'>= '.$current_value[
'lower'];
897 echo $current_value[
'lower'].
' to '.$current_value[
'upper'];
903 $custom_ranges = Array();
905 foreach ($params[
'custom_num_search'] as $key => $num_search_data) {
906 if (!empty($num_search_data[
'name']) && ($current_value[
'lower'] == $num_search_data[
'min']) && ($current_value[
'upper'] == $num_search_data[
'max'])) {
907 $range_name = $num_search_data[
'name'];
912 if ($sub_field ==
'lower') {
913 print array_get_index($current_value,
'lower',
'');
914 }
else if ($sub_field ==
'upper') {
915 print array_get_index($current_value,
'upper',
'');
916 }
else if ($sub_field ==
'') {
942 function _printNumericRange($field_name, $current_value=NULL, $params, $sub_field=
'', $read_only=FALSE)
944 switch (array_get_index($params,
'numeric_search',
'exact')) {
946 if ($sub_field ==
'') {
947 text_box(
'queries_'.$field_name, array_get_index($current_value,
'lower',
''), 5);
952 $current_value = NULL;
954 if (!isset($current_value[
'upper'])) {
955 $current_value[
'upper'] = NULL;
958 if (!isset($current_value[
'lower'])) {
959 $current_value[
'lower'] = NULL;
962 if ($sub_field ==
'lower') {
963 text_box(
'queries_'.$field_name.
'_lower', $current_value[
'lower'], 5);
964 }
else if ($sub_field ==
'upper') {
965 text_box(
'queries_'.$field_name.
'_upper', $current_value[
'upper'], 5);
967 text_box(
'queries_'.$field_name.
'_lower', $current_value[
'lower'], 5);
969 text_box(
'queries_'.$field_name.
'_upper', $current_value[
'upper'], 5);
974 $custom_ranges = Array();
975 foreach ($params[
'custom_num_search'] as $key => $num_search_data) {
976 if (!empty($num_search_data[
'name'])) {
977 $custom_ranges[$key] = $num_search_data[
'name'];
980 if ($sub_field ==
'') {
981 combo_box(
'queries_'.$field_name, $custom_ranges, FALSE, $current_value);
1007 $options[
''] = $cat_set_details[
'unselected_text'];
1010 foreach ($cat_set_details[
'options'] as $code_name => $cat_option) {
1011 $options[$code_name] = $cat_option[
'full_name'];
1015 combo_box(
'category_'.$cat_set_name, $options, FALSE, $default);
1016 $res = ob_get_contents();
1034 $query_var = $field_name.
'_query';
1035 $fields = $this->
attr(
'fields');
1036 if (!isset($fields[$field_name]))
return;
1040 if (isset($_SESSION[
'SQ_LAST_SEARCH'][$this->
id])) {
1041 $query = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name,
'');
1048 $pmap_params = $pmap->getParameters();
1049 if (empty($query) && is_array($pmap_params) && !empty($pmap_params)) {
1051 if (in_array(
'stored_query', $pmap_params)) {
1052 $key_field = array_search(
'stored_query', $pmap_params);
1053 $query = $pmap->getParameterValue($pmap_params[$key_field]);
1057 if (in_array($field_name, $pmap_params)) {
1058 $key_field = array_search($field_name, $pmap_params);
1059 $query = $pmap->getParameterValue($pmap_params[$key_field]);
1061 replace_global_keywords($query);
1066 if (empty($fields[$field_name][
'data_sources']) || $this->
_hasMixedFieldTypes($fields[$field_name])) {
1067 text_box(
'queries_'.$query_var, $query, $this->defaults[
'query_width']);
1070 $data_source = $fields[$field_name][
'data_sources'][0];
1072 switch ($data_source[
'type']) {
1075 $assetid = $data_source[
'params'][
'assetid'];
1076 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1078 if (!is_null($asset)) {
1079 $params = $asset->vars;
1080 switch (get_class_lower($asset)) {
1081 case 'metadata_field_date' :
1082 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1085 case 'metadata_field_text' :
1086 case 'metadata_field_thesaurus':
1087 case 'metadata_field_multiple_text':
1088 case 'metadata_field_wysiwyg':
1089 text_box(
'queries_'.$query_var, $query, $this->defaults[
'query_width']);
1091 case 'metadata_field_hierarchy' :
1092 $hierarchy = $asset->getHierarchyAttribute();
1094 if (!empty($query)) $hierarchy->value = $query;
1095 if ($asset->attr(
'hier_sort')) {
1096 $sort = $asset->attr(
'hier_sort');
1097 $fmt = $asset->attr(
'hier_structure');
1098 $edit_fns = $asset->getEditFns();
1099 $options = $hierarchy->_params[
'options'];
1100 $options = $edit_fns->_sortHierarchyOptions($options, $sort, $fmt);
1101 $hierarchy->_params[
'options'] = $options;
1103 $hierarchy->paint(
'queries_'.$query_var);
1105 case 'metadata_field_select' :
1106 $selection = $asset->getSelectionAttribute();
1107 if (!empty($query)) $selection->setValue($query);
1108 $selection->paint(
'queries_'.$query_var);
1117 case 'asset_attrib' :
1118 $attribute = $GLOBALS[
'SQ_SYSTEM']->am->getAttribute($data_source[
'params'][
'attrid']);
1120 if ($attribute->type() ==
'datetime') {
1122 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1125 }
else if (($attribute->type() ==
'int' || $attribute->type() ==
'float')) {
1131 if ($attribute->type() ==
'boolean' || $attribute->type() ==
'selection') {
1132 $attribute->_params[
'allow_empty'] = TRUE;
1136 $attribute->setValue($query);
1139 $search_styles = $this->
attr(
'search_styles');
1140 if (isset($search_styles[$attribute->id])) {
1141 $attribute->_edit_params = array_merge($attribute->_edit_params, $search_styles[$attribute->id]);
1144 $attribute->paint(
'queries_'.$query_var, FALSE);
1149 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager');
1150 if (isset($sm->standard_date_fields[$data_source[
'params'][
'field']])) {
1151 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1153 }
else if (isset($sm->standard_text_fields[$data_source[
'params'][
'field']])) {
1154 text_box(
'queries_'.$query_var, $query, $this->defaults[
'query_width']);
1159 text_box(
'queries_'.$query_var, $query, $this->defaults[
'query_width']);
1169 $replacement = ob_get_contents();
1173 return $replacement;
1188 $query_var = $field_name.
'_query_sis';
1189 $query = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name,
'');
1190 $fields = $this->
attr(
'fields');
1196 $data_source = $fields[$field_name][
'data_sources'][0];
1198 switch ($data_source[
'type']) {
1201 $assetid = $data_source[
'params'][
'assetid'];
1202 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1203 if (!is_null($asset)) {
1204 $params = $asset->vars;
1206 switch (get_class_lower($asset)) {
1207 case 'metadata_field_date' :
1209 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1212 case 'metadata_field_text' :
1213 case 'metadata_field_thesaurus':
1214 case 'metadata_field_multiple_text':
1215 text_box(
'queries_'.$query_var,
'', $this->defaults[
'query_width']);
1217 case 'metadata_field_hierarchy' :
1218 $hierarchy = $asset->getHierarchyAttribute();
1219 if (!empty($query)) $hierarchy->value = $query;
1220 if ($asset->attr(
'hier_sort')) {
1221 $sort = $asset->attr(
'hier_sort');
1222 $fmt = $asset->attr(
'hier_structure');
1223 $edit_fns = $asset->getEditFns();
1224 $options = $hierarchy->_params[
'options'];
1225 $options = $edit_fns->_sortHierarchyOptions($options, $sort, $fmt);
1226 $hierarchy->_params[
'options'] = $options;
1228 $hierarchy->paint(
'queries_'.$query_var);
1230 case 'metadata_field_select' :
1231 $selection = $asset->getSelectionAttribute();
1234 if (empty($selection->_params[
'multiple'])) {
1235 if (isset($selection->_params[
'options'][$query])) {
1242 $selection->value = $query;
1244 if (!empty($query)) {
1245 echo
'<div class="search_current_options">';
1246 foreach ($query as $option) {
1247 if (!isset($selection->_params[
'options'][$option])) {
1250 echo $selection->_params[
'options'][$option].
'<br />';
1251 unset($selection->_params[
'options'][$option]);
1257 $selection->paint(
'queries_'.$query_var, $read_only);
1267 case 'asset_attrib' :
1268 $attribute = $GLOBALS[
'SQ_SYSTEM']->am->getAttribute($data_source[
'params'][
'attrid']);
1270 if ($attribute->type() ==
'datetime') {
1273 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1274 $this->
_printDateRange(
'queries_'.$query_var, $current_value, $read_only);
1279 if ($attribute->type() ==
'boolean' || $attribute->type() ==
'selection') {
1280 $attribute->_params[
'allow_empty'] = TRUE;
1284 $search_styles = $this->
attr(
'search_styles');
1285 if (isset($search_styles[$attribute->id])) {
1286 $attribute->_edit_params = $search_styles[$attribute->id];
1289 switch ($attribute->type()) {
1291 if (empty($attribute->_params[
'multiple'])) {
1292 if (isset($attribute->_params[
'options'][$query])) {
1296 if (!empty($query)) {
1297 echo
'<div class="search_current_options">';
1298 foreach ($query as $option) {
1299 if (!isset($attribute->_params[
'options'][$option])) {
1302 echo $attribute->_params[
'options'][$option].
'<br />';
1303 unset($attribute->_params[
'options'][$option]);
1311 if ($query !=
'') $read_only = TRUE;
1315 $attribute->value =
'';
1319 $attribute->paint(
'queries_'.$query_var, $read_only);
1325 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager');
1326 if (isset($sm->standard_date_fields[$data_source[
'params'][
'field']])) {
1327 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1328 $this->
_printDateRange(
'queries_'.$query_var, $current_value, $read_only);
1329 }
else if (isset($sm->standard_text_fields[$data_source[
'params'][
'field']])) {
1330 text_box(
'queries_'.$query_var,
'', $this->defaults[
'query_width']);
1336 text_box(
'queries_'.$query_var,
'', $this->defaults[
'query_width']);
1342 text_box(
'queries_'.$query_var, $query, $this->defaults[
'query_width']);
1349 $replacement = ob_get_contents();
1353 return $replacement;
1370 $query_var = $field_name.
'_query_sis';
1371 $query = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name,
'');
1372 $fields = $this->
attr(
'fields');
1377 switch ($fields[$field_name][
'data_sources'][0][
'type']) {
1380 $assetid = $fields[$field_name][
'data_sources'][0][
'params'][
'assetid'];
1381 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1382 if (!is_null($asset)) {
1383 $params = $asset->vars;
1384 switch (get_class_lower($asset)) {
1385 case 'metadata_field_date' :
1386 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1389 case 'metadata_field_text' :
1390 case 'metadata_field_thesaurus':
1391 case 'metadata_field_multiple_text':
1392 echo ($escape ? htmlspecialchars($query) : $query);
1394 case 'metadata_field_hierarchy' :
1395 $hierarchy = $asset->getHierarchyAttribute();
1396 if (!empty($query)) $hierarchy->value = $query;
1397 if ($asset->attr(
'hier_sort')) {
1398 $sort = $asset->attr(
'hier_sort');
1399 $fmt = $asset->attr(
'hier_structure');
1400 $edit_fns = $asset->getEditFns();
1401 $options = $hierarchy->_params[
'options'];
1402 $options = $edit_fns->_sortHierarchyOptions($options, $sort, $fmt);
1403 $hierarchy->_params[
'options'] = $options;
1405 $hierarchy->paint(
'queries_'.$query_var);
1407 case 'metadata_field_select' :
1409 $selection = $asset->getSelectionAttribute();
1410 if (!empty($query)) $selection->setValue($query);
1411 $selection->paint(
'queries_'.$query_var, TRUE);
1418 case 'asset_attrib' :
1419 $attribute = $GLOBALS[
'SQ_SYSTEM']->am->getAttribute($fields[$field_name][
'data_sources'][0][
'params'][
'attrid']);
1421 if ($attribute->type() ==
'datetime') {
1423 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1426 }
else if (($attribute->type() ==
'int' || $attribute->type() ==
'float')) {
1427 $current_value = array_get_index($_SESSION[
'SQ_LAST_SEARCH'][$this->
id], $field_name, Array());
1432 if ($attribute->type() ==
'boolean' || $attribute->type() ==
'selection') {
1433 $attribute->_params[
'allow_empty'] = TRUE;
1437 $search_styles = $this->
attr(
'search_styles');
1438 if (isset($search_styles[$attribute->id])) {
1439 $attribute->_edit_params = $search_styles[$attribute->id];
1442 $attribute->value = $query;
1444 $attribute->paint(
'queries_'.$query_var, TRUE);
1449 if (is_array($query) && isset($query[
'from']) && isset($query[
'to'])) {
1454 echo ($escape ? htmlspecialchars($query) : $query);
1461 echo ($escape ? htmlspecialchars($query) : $query);
1464 $replacement = ob_get_contents();
1468 return $replacement;
1487 case 'search_button' :
1488 case 'submit_button' :
1489 $field_name = $prefix.
'_submit_button';
1491 $this->_tmp[
'prints_submit'] = TRUE;
1495 $mode = array_get_index($_REQUEST,
'mode',
'initial');
1497 $replacement =
'<input type="text" name="'.$prefix.
'_extra_field" id="'.$prefix.
'_extra_field" disabled="disabled" style="display:none" />';
1498 if ($mode ==
'initial') {
1499 $replacement .=
'<input type="submit" name="'.$field_name.
'"
1500 value="'.$this->
attr(
'submit_button_text').
'" />';
1502 $replacement .=
'<input type="submit" name="'.$field_name.
'" onclick="listing_form = document.getElementById(\''.$this->
getPrefix().
'\');
1503 listing_form.current_result_page.value=\
'1\';
1504 if (typeof listing_form.mode != \'undefined\') listing_form.mode.value = \'results\';
1506 " value="'.$this->attr(
'submit_button_text').
'" />';
1510 case 'search_in_search_button' :
1511 $field_name =
'sis_search_button';
1513 $this->_tmp[
'prints_submit'] = TRUE;
1515 $replacement =
'<input type="submit" name="'.$field_name.
'" onclick="listing_form = document.getElementById(\''.$this->
getPrefix().
'\');
1516 listing_form.current_result_page.value=\
'1\';
1517 listing_form.mode.value = \'sis\';
1519 " value="'.$this->attr(
'sis_button_text').
'" />';
1525 if (!empty($bodycopy_link) && $bodycopy_link[
'link_type'] == SQ_LINK_TYPE_2) {
1533 case 'search_in_search_form':
1536 if (!empty($bodycopy_link) && $bodycopy_link[
'link_type'] == SQ_LINK_TYPE_2) {
1544 case 'results_per_page' :
1545 $results_per_page = array_get_index($_REQUEST,
'results_per_page', $this->
_getNumPerPage());
1546 $field_name =
'results_per_page_text_box';
1548 $replacement =
'<input type="text" name="'.$field_name.
'" onchange="listing_form = document.getElementById(\''.$this->
getPrefix().
'\');
1549 listing_form.results_per_page.value = this.value;
1550 " value="'.$results_per_page.'" size="5
" />';
1554 $replacement = $this->getKeywordReplacement($keyword);
1559 return $replacement;
1561 }//end getGeneralReplacement()
1570 function getInitialBodyReplacements()
1572 $bodycopy =& $this->getBodycopy('initial');
1573 $keywords = $bodycopy->getKeywords();
1574 $replaces = Array();
1576 $fields = $this->attr('fields');
1577 $categories = $this->attr('categories');
1579 foreach ($keywords as $keyword) {
1580 if (preg_match('/(.+)_query_logic$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1581 $current_logic = array_get_index($_REQUEST, $keyword, array_get_index($fields[$matches[1]], 'word_logic'));
1583 'AND' => translate('sch_page_format_logic_and'),
1584 'OR' => translate('sch_page_format_logic_or'),
1587 $this->registerFormField($keyword);
1588 combo_box($keyword, $options, FALSE, $current_logic);
1589 $replaces[$keyword] = ob_get_contents();
1591 } else if (preg_match('/(.+)_query_(.+)$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1592 $replaces[$keyword] = $this->getFieldReplacement($matches[1], $matches[2]);
1593 } else if (preg_match('/(.+)_query$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1594 $replaces[$keyword] = $this->getFieldReplacement($matches[1]);
1595 } else if (substr($keyword, -17) == '_category_chooser') {
1596 $cat_name = substr($keyword, 0, -17);
1597 $replaces[$keyword] = $this->getCategoryChooserReplacement($cat_name, $categories[$cat_name]);
1599 $replaces[$keyword] = $this->getGeneralReplacement($keyword);
1605 }//end getInitialBodyReplacements()
1616 function getFormFormatReplacements($form_name)
1618 $bodycopy =& $this->getFormatBodycopy($form_name);
1619 if (is_null($bodycopy)) return Array();
1621 $fields = $this->attr('fields');
1622 $keywords = $bodycopy->getKeywords();
1624 $replacements = Array();
1625 foreach ($keywords as $keyword) {
1626 if (preg_match('/(.+)_query_terms$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1627 $replacements[$keyword] = $this->getSearchedFieldReplacement($matches[1]);
1628 } else if (preg_match('/(.+)_query$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1629 if ($form_name == 'sis_form') {
1630 $replacements[$keyword] = $this->getSisFieldReplacement($matches[1]);
1632 $replacements[$keyword] = $this->getFieldReplacement($matches[1]);
1635 if ($form_name == 'sis_form' || $form_name == 'search_form') {
1636 if (substr($keyword, -17) == '_category_chooser') {
1637 $categories = $this->attr('categories');
1638 $cat_name = substr($keyword, 0, -17);
1639 $selected_option = array_get_index($_REQUEST, 'category_'.$cat_name, '');
1641 $replacements[$keyword] = $this->getCategoryChooserReplacement($cat_name, $categories[$cat_name], $selected_option);
1643 $replacements[$keyword] = $this->getGeneralReplacement($keyword);
1646 $replacements[$keyword] = $this->getGeneralReplacement($keyword);
1651 return $replacements;
1653 }//end getFormFormatReplacements()
1666 function getFormFormatContents($form_name, $replacements)
1668 $bodycopy =& $this->getFormatBodycopy($form_name);
1669 if (is_null($bodycopy)) return '';
1671 $bodycopy->setKeywordReplacements($replacements);
1674 $bodycopy->printBody();
1675 $html = ob_get_contents();
1680 }//end getFormFormatContents()
1697 function filterAssetTypes(&$todo)
1699 // the search manager uses the type_code column in the search indexing table
1700 // to filter on asset types for performance reasons, so we don't need to
1704 }//end filterAssetTypes()
1716 function getResultsBodyReplacements(&$results, $bc_name='results')
1718 $mode = array_get_index($_REQUEST, 'mode', 'results');
1719 $bodycopy =& $this->getBodycopy($bc_name);
1720 $keywords = $bodycopy->getKeywords();
1722 // if we have %page_list_X% keywords in the array before the %result_list%
1723 // rip it off and put it at the end of the array or else it will not be
1724 // replace at all #4527 Matrix search page results has no output for page_list_X keywords
1725 $page_list_keywords = Array();
1726 foreach ($keywords as $index => $keyword) {
1727 if (preg_match('/page_list_([0-9]+)/', $keyword, $matches)) {
1728 $page_list_keywords[] = $keyword;
1729 unset($keywords[$index]);
1733 $keywords = array_merge($keywords, $page_list_keywords);
1734 $replaces = Array();
1736 $listing_result_page = (int) array_get_index($_REQUEST, 'result_'.$this->id.'_result_page', 0);
1737 $search_result_page = (int) array_get_index($_REQUEST, 'current_result_page', 1);
1738 if ($listing_result_page === 0) {
1739 $current_result_page = $search_result_page;
1741 $current_result_page = $listing_result_page;
1743 $results_per_page = array_get_index($_REQUEST, 'results_per_page', $this->_getNumPerPage());
1744 $this->_tmp['start_element'] = ($current_result_page - 1) * $results_per_page;
1746 foreach ($_GET as $query_name => $query_value) {
1747 // skip some get vars that will be added later by the keyword replacements
1748 if (!in_array($query_name, Array('mode', 'current_result_page', 'results_per_page', 'result_'.$this->id.'_result_page'))) {
1749 if (is_array($query_value)) {
1750 foreach ($query_value as $value_index => $value_contents) {
1751 $queries .= '&'.urlencode($query_name).'['.urlencode($value_index).']='.urlencode($value_contents);
1754 $queries .= '&'.urlencode($query_name).'='.urlencode($query_value);
1759 // if we are to use the listing engine stuff then we need to change
1760 // to a getAssetList() style format
1762 if (!empty($results)) {
1763 $sort_info = $this->getSortInfo();
1764 $asset_info = $this->sortAssetList($results, $sort_info);
1767 $this->filterAssetList($asset_info);
1769 if (!is_array($asset_info)) $asset_info = Array();
1771 // Important!!! Missing these values in the overridden Listing Engine type of asset
1772 // will generate numerous notice errors when they try to group the result by asset type
1773 $this->_tmp['assets_info'] = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($asset_info));
1774 $this->_tmp['asset_urls'] = $GLOBALS['SQ_SYSTEM']->am->getAssetURL(array_keys($asset_info));
1776 if ($results_per_page != 0) {
1777 $total_pages = ceil(count($asset_info) / $results_per_page);
1782 // get any extra keyword replacements from asset_listing
1783 $parent_replaces = $this->getContentsKeywordReplacements($keywords);
1784 foreach ($keywords as $keyword) {
1785 $full_keyword = $keyword;
1786 $replacement = "%$full_keyword%
";
1787 $keyword = parse_keyword($keyword, $modifiers);
1788 $apply_modifiers = TRUE;
1792 // the groupAssetsRecursively() method must be called before the getChunk() method because the getChunk()
1793 // method expect the data structure returned by the groupAssetsRecursively() method. Otherwise, there will
1794 // be PHP errors in _groupChunk() function ($todo is not an array like it is expected) if asset grouping
1795 // is used to format the search results
1796 $result_list = $asset_info;
1798 if ($this->attr('group_by') == 'grouped') {
1799 $this->groupAssetsRecursively($this->attr('asset_grouping'), $result_list, $result_list);
1800 $this->sortGroups($this->attr('asset_grouping'), $result_list, $result_list);
1803 $result_list = $this->getChunk($result_list, $parent_replaces, $keywords, $current_result_page, $results_per_page);
1805 // For the 'select all' code
1806 $relations = $this->_analyseCheckAllRelations($result_list);
1808 // print the asset list from the listing engine
1810 $this->printAssetList($result_list);
1811 $replacement = ob_get_contents();
1815 case 'initial_result_count' :
1816 $initial_results = $this->_tmp['initial_results'];
1817 $replacement = count($initial_results);
1820 case 'result_count':
1821 $replacement = $this->_arrayCountRecursive($asset_info);
1824 case 'current_result_page':
1825 $replacement = min($current_result_page, $total_pages);
1828 case 'current_result_page_start':
1829 $start_record = ($current_result_page==1) ? $current_result_page : ((($current_result_page-1)*$results_per_page)+1);
1830 $replacement = $start_record;
1833 case 'current_result_page_end':
1834 $end_record = (($current_result_page) * $results_per_page);
1835 if ($end_record > $this->_arrayCountRecursive($asset_info)) {
1836 $end_record = $this->_arrayCountRecursive($asset_info);
1838 $replacement = $end_record;
1842 case 'total_result_pages':
1843 $replacement = $total_pages;
1846 case 'result_page_index':
1848 $current_page_format = $this->attr('current_page_format');
1849 $page_link_format = $this->attr('page_link_format');
1851 for ($i = 1; $i <= $total_pages; $i++) {
1852 if ($i == $current_result_page) {
1853 $replacement .= str_replace('%page_number%', $i, $current_page_format);
1855 $href = ($this->attr('submit_to_page_url') ? $this->getURL() : current_url()).'?'.htmlspecialchars('mode='.$mode.'¤t_result_page='.$i.'&results_per_page='.$results_per_page.$queries);
1856 $replacement .= str_replace(Array('%page_number%', '%page_link%'), Array($i, $href), $page_link_format);
1861 case 'previous_result_page_link':
1862 if ($current_result_page <= 1) {
1863 $replacement = $this->attr('hide_no_href_links') ? '' : $this->attr('prev_page_text');
1866 $replacement = '<a href="'.($this->attr('submit_to_page_url
') ? $this->getURL() : current_url()).'?
'.htmlspecialchars('mode=
'.$mode.'¤t_result_page=
'.($current_result_page - 1).'&results_per_page=
'.$results_per_page.$queries).'">'.$this->attr('prev_page_text').'</a>';
1869 case 'next_result_page_link':
1870 if ($current_result_page >= $total_pages) {
1871 $replacement = $this->attr('hide_no_href_links') ? '' : $this->attr('next_page_text');
1874 $replacement = '<a href="'.($this->attr('submit_to_page_url
') ? $this->getURL() : current_url()).'?
'.htmlspecialchars('mode=
'.$mode.'¤t_result_page=
'.($current_result_page + 1).'&results_per_page=
'.$results_per_page.$queries).'">'.$this->attr('next_page_text').'</a>';
1877 case 'previous_result_page_href':
1878 if ($current_result_page <= 1) {
1882 $replacement = ($this->attr('submit_to_page_url') ? $this->getURL() : current_url()).'?'.htmlspecialchars('mode='.$mode.'¤t_result_page='.($current_result_page - 1).'&results_per_page='.$results_per_page.$queries);
1885 case 'next_result_page_href':
1886 if ($current_result_page >= $total_pages) {
1890 $replacement = ($this->attr('submit_to_page_url') ? $this->getURL() : current_url()).'?'.htmlspecialchars('mode='.$mode.'¤t_result_page='.($current_result_page + 1).'&results_per_page='.$results_per_page.$queries);
1893 case 'initial_layout':
1894 $replacement = $this->getBodycopyContents('initial', $this->getInitialBodyReplacements());
1898 $fields = $this->attr('fields');
1900 if (preg_match('/(.+)_query_logic$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1902 $current_logic = array_get_index($_REQUEST, $keyword, 'AND');
1903 $options = Array('AND' => translate('sch_page_format_logic_and'), 'OR' => translate('sch_page_format_logic_or'));
1905 $this->registerFormField($keyword);
1906 combo_box($keyword, $options, FALSE, $current_logic);
1907 $replacement = ob_get_contents();
1910 } else if (preg_match('/(.+)_query_terms_(.+)$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1912 $replacement = $this->getSearchedFieldReplacement($matches[1], $matches[2]);
1914 } else if (preg_match('/(.+)_query_terms$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1916 $replacement = $this->getSearchedFieldReplacement($matches[1]);
1918 } else if (preg_match('/(.+)_query_synonym_search_message$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1920 if (!empty($this->_tmp['auto_synonym_search_used'])) {
1921 $replacement = $this->attr('auto_synonym_string');
1924 } else if (preg_match('/(.+)_query_suggestions(_message)?$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1926 // spell-checking suggestions
1927 $field_name = $matches[1];
1928 if (isset($this->_tmp['search_suggestions'][$field_name])) {
1929 $queries_temp = str_replace('queries_'.$field_name.'_query='.urlencode($this->getSearchedFieldReplacement($field_name, '', FALSE)), 'queries_'.$field_name.'_query='.urlencode($this->_tmp['search_suggestions'][$field_name]), $queries);
1930 $spell_check_string = '<a href="'.($this->attr('submit_to_page_url
') ? $this->getURL() : current_url()).'?mode=
'.$mode.'¤t_result_page=
'.$current_result_page.'&results_per_page=
'.$results_per_page.$queries_temp.'">'.htmlspecialchars($this->_tmp['search_suggestions'][$field_name]).'</a>';
1932 $spell_check_string = '';
1935 if (!empty($spell_check_string)) {
1936 if (substr($keyword, -8) == '_message') {
1937 $message = $this->attr('spell_check_string');
1938 $replacement = str_replace('%suggestions%', $spell_check_string, $message);
1940 $replacement = $spell_check_string;
1944 } else if (preg_match('/(.+)_query_synonyms(_message)?$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1946 // synonym searching
1947 $field_name = $matches[1];
1948 $synonym_string = Array();
1949 if (isset($this->_tmp['search_synonyms'])) {
1950 foreach (array_get_index($this->_tmp['search_synonyms'], $field_name, Array()) as $word => $synonyms) {
1951 foreach ($synonyms as $synonym) {
1952 $queries_temp = str_replace('queries_'.$field_name.'_query='.urlencode($this->getSearchedFieldReplacement($field_name, '', FALSE)), 'queries_'.$field_name.'_query='.urlencode($synonym), $queries);
1953 $synonym_string[] = '<a href="'.($this->attr('submit_to_page_url
') ? $this->getURL() : current_url()).'?mode=
'.$mode.'¤t_result_page=
'.$current_result_page.'&results_per_page=
'.$results_per_page.$queries_temp.'">'.htmlspecialchars($synonym).'</a>';
1957 $synonym_string = implode(', ', $synonym_string);
1959 if (!empty($synonym_string)) {
1960 if (substr($keyword, -8) == '_message') {
1961 $message = $this->attr('synonym_string');
1962 $replacement = str_replace('%suggestions%', $synonym_string, $message);
1964 $replacement = $synonym_string;
1968 } else if (preg_match('/(.+)_query_(.+)$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1970 $replacement = $this->getFieldReplacement($matches[1], $matches[2]);
1972 } else if (preg_match('/(.+)_query$/', $keyword, $matches) && array_key_exists($matches[1], $fields)) {
1974 $replacement = $this->getFieldReplacement($matches[1]);
1976 } else if (substr($keyword, -7) == '_linked') {
1978 if ($keyword == 'category_list_linked') {
1979 // printing the list of seach categories
1980 $categories = $this->attr('categories');
1981 if (!empty($categories)) {
1982 $query_string_vars = Array(
1984 'current_result_page' => 1,
1988 <div id="search_category_list
">
1990 foreach ($categories as $cat_name => $cat_data) {
1994 $current_option = array_get_index($_GET, 'category_'.$cat_name, '');
1995 $cat_data['options'] = Array('' => Array('full_name' => $cat_data['unselected_text'])) + $cat_data['options'];
1996 foreach ($cat_data['options'] as $key => $data) {
1997 $query_string_vars['category_'.$cat_name] = $key;
1998 $url = htmlspecialchars(replace_query_string_vars($query_string_vars));
2000 <li<?php echo ($current_option == $key) ? ' id="current
"' : ''; ?>>
2001 <a href="<?php echo $url; ?>
">
2002 <?php echo $data['full_name']; ?>
2007 unset($query_string_vars['category_'.$cat_name]);
2015 $replacement = ob_get_contents();
2021 } else if (substr($keyword, -13) == '_query_linked') {
2024 $not_selected_text = '';
2026 $query_var = substr($keyword, 0, (strlen($keyword) - 13));
2027 $fields = $this->attr('fields');
2029 if ($fields[$query_var]['type'] == 'metadata') {
2031 $assetid = $fields[$query_var]['params']['assetid'];
2032 $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
2033 $params = $asset->vars;
2034 // metadata dropdown selection
2035 if (isset($params['select_options'])) {
2036 $options = $params['select_options']['value'];
2039 } else if ($fields[$query_var]['type'] == 'asset_attrib') {
2041 $search_styles = $this->attr('search_styles');
2042 $not_selected_text = '';
2044 $attribute = $GLOBALS['SQ_SYSTEM']->am->getAttribute($fields[$query_var]['params']['attrid']);
2046 if ($attribute->type() == 'selection') {
2047 if (empty($attribute->_params['multiple'])) {
2048 $options = $attribute->_params['options'];
2050 $not_selected_text = array_get_index($search_styles[$attribute->id], 'empty_text');
2051 } else if ($attribute->type() == 'boolean') {
2052 if (isset($search_styles[$attribute->id])) {
2054 '0' => $search_styles[$attribute->id]['false_text'],
2055 '1' => $search_styles[$attribute->id]['true_text'],
2058 $options = Array('0' => translate('false'), '1' => translate('true'));
2060 $not_selected_text = array_get_index($search_styles[$attribute->id], 'empty_text');
2062 }//end if an attribute
2064 if (!empty($options)) {
2065 $query_key = 'queries_'.$query_var.'_query';
2066 $current_value = (string) array_get_index($_SESSION['SQ_LAST_SEARCH'][$this->id], $query_var, '');
2068 $base_url = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
2069 $base_url = preg_replace('|([&?])mode=([^&]+)|', '\\1mode='.$mode, $base_url);
2070 $base_url = preg_replace('|&'.$query_key.'=([^&]+)?|', '', $base_url);
2071 $base_url = preg_replace('|¤t_result_page=([^&]+)?|', '¤t_result_page=1', $base_url);
2072 $base_url .= '&'.$query_key.'=';
2074 if ($not_selected_text == '') {
2075 $not_selected_text = translate('no_selection');
2079 <div id="search_<?php echo $query_var; ?>_query_list
">
2081 <li<?php echo ($current_value == '') ? ' id="current
"' : ''; ?>>
2082 <a href="<?php echo $base_url; ?>
"><?php echo $not_selected_text; ?></a>
2085 foreach ($options as $key => $value) {
2086 $key = (string) $key;
2088 <li<?php echo ($current_value == $key) ? ' id="current
"' : ''; ?>>
2089 <a href="<?php echo $base_url.$key; ?>
"><?php echo $value; ?></a>
2097 $replacement = ob_get_contents();
2100 }//end if category links
2104 // use the parent's replacement if it exists, otherwise revert to the default
2105 if (isset($parent_replaces[$keyword])) {
2106 $replacement = $parent_replaces[$keyword];
2108 // Avoid messing with globals and other keywords in the fallback to Asset::getKeywordReplacement() by passing the full keyword.
2109 $replacement = $this->getGeneralReplacement($full_keyword);
2110 $apply_modifiers = FALSE;
2117 if ($apply_modifiers && $replacement != "%$full_keyword%
"){
2118 apply_keyword_modifiers($replacement, $modifiers, Array('assetid' => $this->id));
2121 $replaces[$full_keyword] = $replacement;
2127 }//end getResultsBodyReplacements()
2138 function getResultElementBodyReplacements($assetid)
2140 $bodycopy =& $this->getBodycopy('result_element');
2141 $keywords = $bodycopy->getKeywords();
2143 $am =& $GLOBALS['SQ_SYSTEM']->am;
2144 $asset = $am->getAsset($assetid);
2146 $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
2147 $replaces = $mm->generateKeywordReplacements($asset, $keywords, FALSE);
2149 $metadata_keywords = Array();
2150 foreach ($keywords as $key) {
2151 if (substr($key, 0, 15) == 'asset_metadata_') {
2152 $metadata_keywords[$key] = substr($key, 15);
2155 if (!empty($metadata_keywords)) {
2156 $metadata_values = $mm->getMetadataFieldValues($assetid, array_values($metadata_keywords));
2157 foreach ($metadata_keywords as $key => $field) {
2158 if (isset($metadata_values[$field])) {
2159 $replaces[$key] = $metadata_values[$field];
2164 $asset_keywords = $asset->getAvailableKeywords();
2165 foreach ($asset_keywords as $key => $description) {
2166 if (in_array($key, $keywords)) {
2167 $replaces[$key] = $asset->getKeywordReplacement($key);
2171 foreach ($keywords as $keyword) {
2173 $replacement =& $replaces[$keyword];
2176 $replacement = $assetid;
2179 case 'asset_name_linked':
2180 $replacement = '<a href="'.$asset->getUrl().'">'.$asset->name.'</a>';
2183 case 'asset_short_name_linked':
2184 $replacement = '<a href="'.$asset->getUrl().'">'.$asset->short_name.'</a>';
2187 case 'asset_lineage':
2188 case 'asset_lineage_linked':
2191 $found_root = FALSE;
2192 $nurl = $asset->getUrl();
2193 $unrl = strip_url($nurl);
2194 $nurl = stristr($nurl,'/');
2195 $nurl = substr($nurl,2);
2196 $parent_asset_ids = $am->getLineageFromURL(NULL,$nurl);
2197 // searching for the root asset
2198 $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, '', FALSE, 'root');
2199 $root_assetid = empty($root_link) ? 0 : $root_link['minorid'];
2200 foreach ($parent_asset_ids as $parent_asset_id) {
2201 if ($parent_asset_id == $root_assetid) {
2204 if (!$found_root) continue;
2206 $replacement .= $this->attr('lineage_seperator');
2209 $ancestor_asset = $am->getAsset($parent_asset_id);
2210 if ($keyword == 'asset_lineage_linked') {
2211 $replacement .= '<a href="'.$ancestor_asset->getUrl().'">';
2213 $replacement .= $ancestor_asset->short_name;
2214 if ($keyword == 'asset_lineage_linked') {
2215 $replacement .= '</a>';
2217 $am->forgetAsset($ancestor_asset);
2225 }//end getResultElementBodyReplacements()
2239 function getExtendedAssetKeywordReplacements()
2241 // We are only replacing them with their own replacement so they can be
2242 // cached out like this, then score and result number can be added later
2244 'result_number' => '%result_number%',
2245 'score' => '%score%',
2248 }//end getExtendedAssetKeywordReplacements()
2262 function _addDateRangeRestriction (&$fields, &$queries)
2264 $restrict_date_field = $this->attr('restrict_date_field');
2265 $to = $this->getAttribute('restrict_date_range_to');
2266 $from = $this->getAttribute('restrict_date_range_from');
2268 // return if restriction is not set
2269 if(empty($restrict_date_field) || ( $to->value === '---------- --:--:--' && $from->value === '---------- --:--:--')) {
2272 $from = $from->getISO8601();
2273 $from_date = iso8601_date_component($from);
2274 if (!empty($from_date)) {
2275 // invalid FROM date?
2276 if (!preg_match_all('|^\d{4}-\d{2}-\d{2}$|', $from_date, $matches)) {
2277 trigger_localised_error('CMS0053', E_USER_WARNING, $from_date);
2281 $from_time = iso8601_time_component($from);
2282 if (empty($from_time)) $from_time = '00:00:00';
2284 // invalid FROM time?
2285 if (!preg_match_all('|^\d{2}:\d{2}:\d{2}$|', $from_time, $matches)) {
2286 trigger_localised_error('CMS0054', E_USER_WARNING, $from_time);
2289 $restrict_date_range_from = $from_date.' '.$from_time;
2292 $to = $to->getISO8601();
2293 $to_date = iso8601_date_component($to);
2294 if (!empty($to_date)) {
2296 if (!preg_match_all('|^\d{4}-\d{2}-\d{2}$|', $to_date, $matches)) {
2297 trigger_localised_error('CMS0055', E_USER_WARNING, $to_date);
2301 $to_time = iso8601_time_component($to);
2302 if (empty($to_time)) $to_time = '23:59:59';
2305 if (!preg_match_all('|^\d{2}:\d{2}:\d{2}$|', $to_time, $matches)) {
2306 trigger_localised_error('CMS0056', E_USER_WARNING, $to_time);
2309 $restrict_date_range_to = $to_date.' '.$to_time;
2313 $content['name'] = 'matrix_search_page_date_range';
2314 $content['word_logic'] = 'AND';
2315 $content['specific_field_logic'] = 'AND';
2316 $content['data_sources'] = Array (
2318 'type' => 'standard',
2319 'params' => Array ('field' => $restrict_date_field)
2322 $fields['matrix_search_page_date_range'] = $content;
2323 $queries['matrix_search_page_date_range'] = Array (
2324 'from' => isset($restrict_date_range_from) ? $restrict_date_range_from : '---------- --:--:--',
2325 'to' => isset($restrict_date_range_to) ? $restrict_date_range_to : '---------- --:--:--'
2327 }//end _addDateRangeRestriction()
2343 function processSearch($search=Array())
2345 $sm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
2347 $fields = $this->attr('fields');
2348 $queries = $this->_getSearchedQueries();
2350 // Add date range restriction as a search field and query.
2351 $this->_addDateRangeRestriction($fields, $queries);
2353 // If the search params were passed, get them and use them, if the search queries are empty
2354 if (!empty($search) || count($search)>0) {
2355 foreach ($search as $search_key => $search_value) {
2356 if (!isset($_REQUEST['queries_'.$search_key.'_query_posted'])) {
2357 if (!isset($queries[$search_key]) || empty($queries[$search_key])) {
2358 $queries[$search_key] = $search_value;
2364 // check if we are allowing the keywords to be replaced in user input
2365 if($this->attr('disable_keyword_replacements')) {
2366 $queries = $this->_sanitizeQueries($queries);
2369 // save the search terms into the session so that we can use them for
2370 // search within search results
2371 $_SESSION['SQ_LAST_SEARCH'][$this->id] = $queries;
2373 // get the basic search settings based on the current category (if any)
2374 $search_info = $this->populateBaseSearchInfo();
2375 if (empty($search_info['fields'])) {
2376 $search_info['fields'] = Array();
2379 $query_fields_exist = FALSE;
2381 foreach ($queries as $field_name => $value) {
2383 if (empty($value)) continue;
2385 $empty_numeric = Array(
2389 if ($value == $empty_numeric) continue;
2391 $empty_dates = Array(
2392 'from' => '---------- --:--:--',
2393 'to' => '---------- --:--:--',
2395 if ($value == $empty_dates) continue;
2397 if (count($fields[$field_name]['data_sources']) == 0) {
2398 trigger_localised_error('SCH0028', E_USER_NOTICE, $field_name);
2402 if (!$this->_hasMixedFieldTypes($fields[$field_name]) && $fields[$field_name]['data_sources'][0]['type'] == 'asset_attrib') {
2403 $attribute = $GLOBALS['SQ_SYSTEM']->am->getAttribute($fields[$field_name]['data_sources'][0]['params']['attrid']);
2404 if (!is_null($attribute) && $attribute->type() == 'boolean') {
2405 // we need to convert the value into a word representation,
2406 // since indexing service will not operate just 0 or 1
2407 // do not localise this!!
2408 if ($value == '0') {
2410 } else if ($value == '1') {
2415 $search_info['fields'][$field_name] = $fields[$field_name];
2416 $search_info['fields'][$field_name]['words'] = $value;
2417 $search_info['fields'][$field_name]['exclude_field'] = array_get_index($fields[$field_name], 'exclude_field', FALSE);
2419 // If there is aleast one "regular
" search field, we have the query fields
2420 if (!$search_info['fields'][$field_name]['exclude_field']) {
2421 $query_fields_exist = TRUE;
2424 $submitted_word_logic = strtoupper(array_get_index($_REQUEST, $field_name.'_query_logic', ''));
2425 if (in_array($submitted_word_logic, Array('AND', 'OR'))) {
2426 $search_info['fields'][$field_name]['word_logic'] = $submitted_word_logic;
2429 }//end foreach fields
2431 // spell-check suggestions
2432 if (!empty($search_info['fields'])) {
2433 foreach ($search_info['fields'] as $field_name => $field_content) {
2434 $words = $field_content['words'];
2435 if (!is_array($words)) $words = explode(' ', $words);
2436 if ($sm->spellCheckAvailable()) {
2437 // suggestion 'string' - this will be imploded later with spaces
2438 $suggestion_string = Array();
2439 $needs_suggestions = FALSE;
2441 // loop over each word
2442 foreach ($words as $word) {
2444 // figure out quote positioning
2445 preg_match_all('/"/
', $word, $raw_positions, PREG_OFFSET_CAPTURE);
2446 $quote_positions = Array();
2447 if (!empty($raw_positions)) {
2448 foreach ($raw_positions[0] as $position) {
2449 $quote_positions[] = $position[1];
2453 $suggestions = $sm->spellCheckWord($word);
2454 if (!empty($suggestions)) {
2455 $needs_suggestions = TRUE;
2456 $suggestion = $suggestions[0];
2458 foreach ($quote_positions as $position) {
2459 // we can easily re-add quotes to the beginning and
2460 // end of a word, but in the middle is a bit tricky
2461 if ($position == 0) {
2462 $suggestion = '"'.$suggestion;
2463 } else if ($position == strlen($word) - 1) {
2464 $suggestion = $suggestion.'"';
2468 $suggestion_string[] = $suggestion;
2470 $suggestion_string[] = $word;
2474 if ($needs_suggestions) {
2475 $this->_tmp['search_suggestions
'][$field_name] = implode(' ', $suggestion_string);
2477 }//end if spell check available
2479 // thesaurus synonym searching
2480 $t_link = $GLOBALS['SQ_SYSTEM
']->am->getLink($this->id, SQ_LINK_NOTICE, 'asset
', FALSE, 'thesaurus
');
2482 $synonyms =& $this->_tmp['search_synonyms
'];
2484 if (!empty($t_link)) {
2485 $thesaurus = $GLOBALS['SQ_SYSTEM
']->am->getAsset($t_link['minorid
']);
2486 $synonyms[$field_name] = Array();
2488 // loop over each word, find synonyms
2489 foreach ($words as $word) {
2490 if (!isset($synonyms[$field_name][$word])) {
2491 $synonyms[$field_name][$word] = $thesaurus->getSynonymsForTerm($word);
2494 }//end thesaurus exists
2498 // Metadata Hierarchy
2499 // requires us to go back up and down the tree we have to add the extra looking here
2500 if (isset($search_info['fields
'])) {
2501 foreach ($search_info['fields
'] as $fieldname => $field) {
2502 foreach ($field['data_sources
'] as $data_src) {
2503 if (isset($data_src['type']) && $data_src['type'] == 'metadata
') {
2504 if (isset($data_src['params
']['assetid
'])) {
2505 $m_field_id = $data_src['params
']['assetid
'];
2507 if ($m_field_id > 0) {
2508 $m_field = $GLOBALS['SQ_SYSTEM
']->am->getAsset($m_field_id);
2509 if (!is_null($m_field)) {
2510 if ($m_field->type() == 'metadata_field_hierarchy
') {
2511 $options = $m_field->attr('hierarchy_options
');
2512 $depth = $m_field->attr('hier_depth
');
2513 $edit_fns = $m_field->getEditFns();
2514 if (is_array($search_info['fields
'][$fieldname]['words
'])) {
2515 // If multiple entries submitted, they arrive as an array, so convert to string
2516 $word_list = implode(' ', $search_info['fields
'][$fieldname]['words
']);
2517 $search_info['fields
'][$fieldname]['words
'] = $word_list;
2519 $search_info['fields
'][$fieldname]['words
'] = $edit_fns->getHierarchyTree($search_info['fields
'][$fieldname]['words
'], $options, ' ');
2520 $search_info['fields
'][$fieldname]['word_logic
'] = 'OR
';
2527 // Seperate "exclude" fields from regular "search" fields
2528 if ($field['exclude_field
']) {
2529 $search_info['exclude
'][$fieldname] = $search_info['fields
'][$fieldname];
2530 unset($search_info['fields
'][$fieldname]);
2536 if ($query_fields_exist) {
2538 // If date range restriction is the only query field set, it's actually an empty search.
2540 if(!$this->
attr(
'allow_empty_search') && count($search_info[
'fields']) == 1 && isset($search_info[
'fields'][
'matrix_search_page_date_range'])){
2544 $auto_ss_field = $this->
attr(
'auto_synonym_search_field');
2545 $search_results = $sm->processSearch($search_info);
2547 if (($this->
attr(
'enable_multi_word_synonym_lookups')) && (!empty($auto_ss_field))) {
2553 if (empty($search_results)) {
2554 if (!empty($auto_ss_field) && isset($search_info[
'fields'][$auto_ss_field])) {
2557 $syn_search_info = $search_info;
2558 $this->_tmp[
'auto_synonym_search_used'] = TRUE;
2560 $search_field = $search_info[
'fields'][$auto_ss_field];
2561 $words = $search_field[
'words'];
2562 if (!is_array($words)) $words = explode(
' ', $words);
2565 $synonym_words = Array();
2573 foreach ($words as $word) {
2574 $synonym_words += $synonyms[$auto_ss_field][$word];
2577 if (!empty($synonym_words)) {
2578 $syn_search_info[
'fields'][$auto_ss_field][
'words'] = implode(
' ', $synonym_words);
2579 $search_results = $sm->processSearch($syn_search_info);
2585 return $search_results;
2587 }
else if ($this->
attr(
'allow_empty_search')) {
2588 return $sm->processBasicSearch($search_info);
2609 private function _getWordCombinations(Array $words)
2611 $word_combinations = Array();
2614 $num_words = count($words);
2615 if ($num_words < 3) {
2616 return Array(implode(
' ', $words));
2621 for ($chunk_size=$num_words; $chunk_size >= 2; $chunk_size--)
2623 for ($start_index=0; $start_index <= $num_words - $chunk_size; $start_index++)
2626 for ($n=0; $n < $chunk_size; $n++)
2628 $word_index = $start_index + $n;
2629 $combination .= $words[$word_index].
' ';
2633 $word_combinations[] = rtrim($combination);
2637 return $word_combinations;
2653 if (isset($this->_tmp[
'searched_queries'])) {
2654 return $this->_tmp[
'searched_queries'];
2657 $fields = $this->
attr(
'fields');
2658 $mode = array_get_index($_REQUEST,
'mode',
'results');
2659 if ($mode ==
'') $mode =
'results';
2660 $suffix = ($mode ==
'results') ?
'_query' :
'_query_sis';
2662 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager');
2663 foreach ($fields as $field_name => $field_details) {
2665 $queries[$field_name] =
'';
2666 $query_var =
'queries_'.$field_name.$suffix;
2671 $clean_query_var = str_replace(
'.',
'_', $query_var);
2673 if (!empty($field_details[
'data_sources']) && !$this->
_hasMixedFieldTypes($field_details)) {
2674 $data_source = $field_details[
'data_sources'][0];
2675 switch ($data_source[
'type']) {
2676 case 'include_all' :
2677 $queries[$field_name] = array_get_index($_REQUEST, $clean_query_var,
'');
2681 if (isset($sm->standard_date_fields[$data_source[
'params'][
'field']])) {
2683 }
else if (isset($sm->standard_text_fields[$data_source[
'params'][
'field']])) {
2684 $queries[$field_name] = array_get_index($_REQUEST, $clean_query_var,
'');
2688 case 'asset_attrib' :
2689 $attribute = $GLOBALS[
'SQ_SYSTEM']->am->getAttribute($data_source[
'params'][
'attrid']);
2690 if (!is_null($attribute)) {
2691 if ($attribute->type() ==
'datetime') {
2693 }
else if (($attribute->type() ==
'int') || ($attribute->type() ==
'float')) {
2694 $queries[$field_name] = Array();
2696 switch (array_get_index($data_source[
'params'],
'numeric_search',
'exact')) {
2698 $query = array_get_index($_REQUEST, $clean_query_var, NULL);
2699 if (!is_null($query)) {
2700 $queries[$field_name][
'lower'] = $query;
2701 $queries[$field_name][
'upper'] = $queries[$field_name][
'lower'];
2706 $query_lower = array_get_index($_REQUEST, $clean_query_var.
'_lower', NULL);
2707 $query_upper = array_get_index($_REQUEST, $clean_query_var.
'_upper', NULL);
2708 if (!is_null($query_lower) || !is_null($query_upper)) {
2709 $queries[$field_name][
'lower'] = ($query_lower ==
'') ? NULL : $query_lower;
2710 $queries[$field_name][
'upper'] = ($query_upper ==
'') ? NULL : $query_upper;
2715 $key = array_get_index($_REQUEST, $clean_query_var, NULL);
2717 if (!is_null($key)) {
2718 $custom_range = array_get_index($data_source[
'params'][
'custom_num_search'], $key, Array());
2719 $queries[$field_name][
'lower'] = ($custom_range[
'min'] ==
'') ? NULL : $custom_range[
'min'];
2720 $queries[$field_name][
'upper'] = ($custom_range[
'max'] ==
'') ? NULL : $custom_range[
'max'];
2725 if ($attribute->type() ==
'boolean' || $attribute->type() ==
'selection') {
2726 $attribute->_params[
'allow_empty'] = TRUE;
2728 $attribute->process($query_var);
2729 $queries[$field_name] = trim($attribute->value);
2730 if ($attribute->type() ==
'selection' && !empty($attribute->_params[
'multiple'])) {
2731 $queries[$field_name] = array_keys($attribute->getValueArray());
2738 if (empty($data_source[
'params'][
'assetid'])) {
2739 trigger_localised_error(
'SCH0027', E_USER_NOTICE, $field_name);
2740 $queries[$field_name] =
'';
2743 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($data_source[
'params'][
'assetid']);
2744 if (!is_null($asset)) {
2745 $params = $asset->vars;
2746 switch (get_class_lower($asset)) {
2747 case 'metadata_field_date' :
2752 $queries[$field_name] = array_get_index($_REQUEST, $clean_query_var,
'');
2759 $queries[$field_name] = array_get_index($_REQUEST, $clean_query_var,
'');
2764 if ($mode ==
'sis') {
2765 $last_search = $_SESSION[
'SQ_LAST_SEARCH'][$this->id];
2767 foreach ($queries as $field_name => $value) {
2769 if (is_scalar($value)) $value = trim($value);
2770 if (empty($value))
continue;
2771 $empty_dates = Array(
2772 'from' =>
'---------- --:--:--',
2773 'to' =>
'---------- --:--:--',
2775 if ($value == $empty_dates)
continue;
2777 if (!isset($last_search[$field_name]) || $last_search[$field_name] ==
'') {
2778 $last_search[$field_name] = $value;
2781 if (is_scalar($last_search[$field_name])) {
2782 $last_search[$field_name] = trim($last_search[$field_name]);
2784 if (!is_array($value)) {
2785 $last_search[$field_name] .=
' '.$value;
2786 }
else if (isset($value[
'from']) || isset($value[
'to'])) {
2788 if (isset($value[
'from'])) {
2789 $last_search[$field_name][
'from'] = $value[
'from'];
2791 if (isset($value[
'to'])) {
2792 $last_search[$field_name][
'to'] = $value[
'to'];
2795 $last_search[$field_name] = array_merge($value, $last_search[$field_name]);
2800 $queries = $last_search;
2805 if (empty($queries) && !empty($this->_tmp[
'potential_searched_queries'])) {
2806 $queries = $this->_tmp[
'potential_searched_queries'];
2825 $categories = $this->
attr(
'categories');
2826 $active_cats = Array();
2827 foreach ($categories as $set_name => $cat_data) {
2828 if (!empty($_GET[
'category_'.$set_name])) {
2829 if (isset($cat_data[
'options'][$_GET[
'category_'.$set_name]])) {
2830 $code_name = $_GET[
'category_'.$set_name];
2831 $active_cats[$set_name.
'_'.$code_name] = $cat_data[
'options'][$code_name];
2836 $search_roots = Array();
2837 $statuses_customised = FALSE;
2838 $root_logic =
'AND';
2839 if (!empty($active_cats)) {
2840 include_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
2841 $search_statuses = array_keys(get_status_names());
2842 foreach ($active_cats as $set_option_name => $cat) {
2843 if (isset($cat[
'statuses'])) {
2844 $statuses_customised = TRUE;
2845 $search_statuses = array_intersect($search_statuses, $cat[
'statuses']);
2847 if (isset($cat[
'root_assetid'])) {
2848 $link_value =
'root_'.$set_option_name;
2849 $root_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'', FALSE, $link_value);
2850 $root_id = array_get_index($root_link,
'minorid');
2851 if ($root_id) $search_roots[] = $root_id;
2856 if (!$statuses_customised) {
2858 $search_statuses = $this->
attr(
'statuses');
2861 if (empty($search_roots)) {
2866 if (empty($search_roots)) $search_roots = 0;
2869 $search_info = Array();
2870 $search_info[
'statuses'] = $search_statuses;
2871 $search_info[
'roots'] = $search_roots;
2872 $search_info[
'root_logic'] = $root_logic;
2873 $search_info[
'field_logic'] = $this->
attr(
'logic');
2874 $search_info[
'requester'] = $this->id;
2875 $search_info[
'asset_types'] = $this->
attr(
'types');
2876 $search_info[
'search_as_public_user'] = $this->
attr(
'search_as_public_user');
2877 $search_info[
'no_roles_check'] = $this->
attr(
'no_roles_check');
2878 $search_info[
'no_group_access_check'] = $this->
attr(
'no_group_access_check');
2880 return $search_info;
2893 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'folder', TRUE,
'major',
'format_folder');
2894 return (!empty($link)) ? $link[0] : Array();
2910 if (!empty($link)) {
2911 $folder = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
2930 if (is_null($format_folder))
return Array();
2932 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($format_folder->id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'bodycopy', TRUE,
'major', $link_value);
2933 return (!empty($link)) ? $link[0] : Array();
2954 if (!empty($bodycopy_link)) {
2955 $bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bodycopy_link[
'minorid'], $bodycopy_link[
'minor_type_code']);
2978 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
2979 $cache_key = $assetid.
'-ctx'.$contextid;
2982 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
2983 $element_contents = $cm->loadFromCache($this->
id, $this->
type(), $cache_key);
2985 if ($element_contents === FALSE) {
2990 parent::_printAsset($assetid, $list_position, $num_items);
2992 $element_contents = ob_get_contents();
2994 $cm->saveToCache($this->
id, $this->
type(), $cache_key, $element_contents);
2998 $score =& $this->_tmp[
'search_results'];
2999 $score = (isset($score[
'type_code'])) ? $score[
'type_code'] : $score;
3000 $weight = (is_array($score[$assetid])) ? $score[$assetid][0][
'weight'] : $score[$assetid];
3002 $element_replacements = Array(
3004 'result_number' => $this->_tmp[
'start_element'] + $list_position,
3008 replace_keywords($element_contents, $element_replacements);
3010 echo $element_contents;
3029 if (empty($field_name))
return '';
3031 $fields = $this->
attr(
'fields');
3032 $field_data = array_get_index($fields, $field_name);
3033 if (empty($field_data))
return '';
3035 $query_var =
'queries_'.$field_name.
'_query';
3036 $field_value = array_get_index($_REQUEST, $query_var,
'');
3038 if (empty($field_value) && isset($_SESSION[
'SQ_LAST_SEARCH'][$this->
id][$field_name])) {
3039 $field_value = $_SESSION[
'SQ_LAST_SEARCH'][$this->id][$field_name];
3042 return $field_value;
3062 $vars[
'keywords'] = isset($vars[
'keywords']) ? $vars[
'keywords'] : Array();
3064 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'bodycopy', TRUE);
3065 $bodycopy_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'bodycopy');
3070 if (!empty($sis_bodycopy_link)) {
3071 $bodycopy_links[] = $sis_bodycopy_link;
3077 if (!empty($search_bodycopy_link)) {
3078 $bodycopy_links[] = $search_bodycopy_link;
3081 $bodycopies = Array();
3082 $type_formats = Array();
3083 $keywords = Array();
3085 foreach ($bodycopy_links as $link_info) {
3086 if (isset($parents[$link_info[
'minorid']])) {
3087 $bodycopies[] = $link_info[
'value'];
3094 if (empty($bodycopies)) {
3095 parent::onRequestKeywords($broadcaster, $vars);
3101 $search_customised = !empty($search_bodycopy_link) && $search_bodycopy_link[
'link_type'] != SQ_LINK_TYPE_3;
3102 $sis_customised = !empty($sis_bodycopy_link) && $sis_bodycopy_link[
'link_type'] != SQ_LINK_TYPE_3;
3104 foreach ($bodycopies as $bodycopy) {
3105 if ($bodycopy ==
'initial' || $bodycopy ==
'sis_form' || $bodycopy ==
'search_form') {
3107 $fields = $this->
attr(
'fields');
3108 foreach ($fields as $field => $field_data) {
3109 $keywords[$field.
'_query'] = translate(
'sch_page_keyword_search_field', $field);
3110 if ($bodycopy ==
'initial') {
3111 $keywords[$field.
'_query_logic'] = translate(
'sch_page_keyword_search_field_logic', $field);
3115 foreach ($this->
attr(
'categories') as $cat_name => $cat_details) {
3116 $keywords[$cat_name.
'_category_chooser'] =
'Dropdown box for category set '.$cat_name;
3121 if ($bodycopy ==
'search_form') {
3122 $keywords[
'submit_button'] = translate(
'cms_listing_keyword_submit_button');
3124 if ($bodycopy ==
'sis_form') {
3125 $keywords[
'search_in_search_button'] = translate(
'sch_page_keyword_sis_button');
3128 if ($bodycopy !=
'sis_form' && $bodycopy !=
'search_form') {
3129 foreach ($this->keywords[$bodycopy] as $keyword) {
3130 $keywords[$keyword] = ucwords(str_replace(
'_',
' ', $keyword));
3134 if ($search_customised) {
3139 if ($sis_customised && $bodycopy ==
'results') {
3145 $vars[
'keywords'] = array_merge($vars[
'keywords'], $keywords);
3161 $keywords = parent::_getAdditionalSingleAssetFormatKeywords();
3163 $keywords[
'result_number'] = translate(
'sch_page_keyword_result_number');
3164 $keywords[
'score'] = translate(
'sch_page_keyword_search_score');
3179 $keywords = Array();
3181 $keywords[
'search_form'] = translate(
'sch_page_keyword_search_form');
3196 $keywords = Array();
3198 $keywords[
'search_form'] = translate(
'sch_page_keyword_search_form');
3199 $keywords[
'search_in_search_form'] = translate(
'sch_page_keyword_sis_form');
3200 $keywords[
'search_in_search_button'] = translate(
'sch_page_keyword_sis_button');
3221 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager');
3223 $search_field = $original_search_info[
'fields'][$auto_ss_field];
3224 $words = $search_field[
'words'];
3225 if (!is_array($words)) $words = explode(
' ', $words);
3228 $syn_search_info = $original_search_info;
3230 $synonym_words = Array();
3231 $word_combinations = $this->_getWordCombinations($words);
3233 $search_logic = Array();
3234 $search_string = $syn_search_info[
'fields'][$auto_ss_field][
'words'];
3237 if (count($words) == 2) {
3238 $word_combinations[] = $words[0];
3239 $word_combinations[] = $words[1];
3242 foreach ($word_combinations as $word_combination) {
3244 $num_synonyms = count($combination_synonyms);
3245 $synonym_words += $combination_synonyms;
3248 if ($num_synonyms > 0) {
3249 $search_logic[$word_combination] = $combination_synonyms;
3252 $search_string = str_ireplace($word_combination,
'', $search_string);
3257 if (!empty($synonym_words)) {
3264 $syn_search_results = Array();
3268 $syn_search_info[
'fields'][$auto_ss_field][
'words'] = $search_string;
3271 $outer_word_logic = $syn_search_info[
'fields'][$auto_ss_field][
'word_logic'];
3274 $initial_search_results = Array();
3275 if (!empty($search_string)) {
3276 $initial_search_results = $sm->processSearch($syn_search_info);
3282 if (($outer_word_logic ==
'AND') && (empty($initial_search_results))) {
3283 return $original_search_results;
3287 $common_search_results = Array();
3288 foreach ($initial_search_results as $result => $weighting) {
3289 $common_search_results[][$result] = $weighting;
3294 foreach ($search_logic as $original_term => $matching_synonyms) {
3296 $syn_search_info = $original_search_info;
3297 $syn_search_info[
'fields'][$auto_ss_field][
'words'] = $original_term;
3298 $term_exploded = explode(
' ', $original_term);
3301 if (count($term_exploded) > 1) {
3302 $syn_search_info[
'fields'][$auto_ss_field][
'word_logic'] =
'AND';
3305 $term_search_results = Array();
3307 $results = $sm->processSearch($syn_search_info);
3308 if (count($results) > 0) {
3309 foreach ($results as $result => $weighting) {
3310 if (isset($term_search_results[$result])) {
3311 $term_search_results[$result] += $weighting;
3313 $term_search_results[$result] = $weighting;
3319 $synonym_term_search_results = Array();
3320 foreach ($matching_synonyms as $matching_synonym) {
3321 $syn_search_info = $original_search_info;
3322 $syn_search_info[
'fields'][$auto_ss_field][
'words'] = $matching_synonym;
3323 $term_exploded = explode(
' ', $matching_synonym);
3326 if (count($term_exploded) > 1) {
3327 $syn_search_info[
'fields'][$auto_ss_field][
'word_logic'] =
'AND';
3330 $results = $sm->processSearch($syn_search_info);
3331 if (count($results) > 0) {
3332 foreach ($results as $result => $weighting) {
3333 if (isset($term_search_results[$result])) {
3334 $term_search_results[$result] += $weighting;
3336 $term_search_results[$result] = $weighting;
3342 $common_search_results[] = $term_search_results;
3346 $synonym_search_results = Array();
3347 if ($outer_word_logic ==
'AND') {
3351 foreach ($common_search_results as $result) {
3353 if (!empty($result)) {
3354 $common = array_keys($result);
3358 foreach ($result as $asset_id => $weighting) {
3361 if ($first_time || (!$first_time && in_array($asset_id, $common))) {
3362 if (isset($synonym_search_results[$asset_id])) {
3363 $synonym_search_results[$asset_id] += $weighting;
3365 $synonym_search_results[$asset_id] = $weighting;
3370 $first_time = FALSE;
3374 foreach ($common_search_results as $result) {
3375 foreach ($result as $asset_id => $weighting) {
3376 if (isset($synonym_search_results[$asset_id])) {
3377 $synonym_search_results[$asset_id] += $weighting;
3379 $synonym_search_results[$asset_id] = $weighting;
3386 foreach ($original_search_results as $result => $weighting) {
3387 if (isset($synonym_search_results[$result])) {
3388 $synonym_search_results[$result] += $weighting;
3390 $synonym_search_results[$result] = $weighting;
3395 $original_search_results = $synonym_search_results;
3398 return $original_search_results;
3412 private function _sanitizeQueries(Array $queries)
3414 foreach($queries as $field => $query) {
3415 if(is_array($query)) {
3416 $queries[$field] = $this->_sanitizeQueries($query);
3420 $keywords = extract_keywords($query);
3421 foreach ($keywords as $keyword) {
3422 $pattern =
'/(%*)'.$keyword.
'(%*)/';
3423 $query = preg_replace($pattern, $keyword, $query);
3425 $queries[$field] = $query;
3444 $search_vars = Array();
3448 $pmap_params = $pmap->getParameters();
3449 $fields = $this->
attr(
'fields');
3450 $this->_tmp[
'jump_to_result'] = FALSE;
3451 if (is_array($pmap_params) && !empty($pmap_params)) {
3452 foreach ($pmap_params as $params) {
3453 $sq_index = $pmap->getParameterValue($params);
3455 if (!is_null($sq_index)) {
3456 replace_global_keywords($sq_index);
3458 $sq_index = str_replace(
'|',
' ', $sq_index);
3461 if ($params ==
'stored_query') {
3463 foreach ($fields as $fieldname => $fieldvalue) {
3464 $search_vars[$fieldname] = $sq_index;
3468 $search_vars[$params] = $sq_index;
3472 if (isset($this->_tmp[
'searched_queries']) && empty($this->_tmp[
'searched_queries'])) {
3473 unset($this->_tmp[
'searched_queries']);
3477 $this->_tmp[
'jump_to_result'] = TRUE;
3483 return $search_vars;