17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
42 $this->_hipo_vars[
'job_dir'] = SQ_PACKAGES_PATH.
'/packages/search/tools/tool_search_replace';
43 $GLOBALS[
'SQ_SYSTEM']->lm->includeAssetStrings(
'tool_search_replace');
57 return parent::getCodeName().
'-'.md5(implode(
'-',array_keys($this->_running_vars[
'search_data'])));
70 return translate(
'sch_hipo_name_global_sr');
86 'name' => translate(
'hipo_confirmation'),
87 'function_call' => Array(
88 'paint_function' =>
'paintConfirmation',
89 'process_function' =>
'processConfirmation',
91 'running_mode' =>
'web',
94 'allow_cancel' => TRUE,
100 'name' => translate(
'hipo_acquiring_locks'),
102 'init_details_function' =>
'getLockAssetDetails',
104 'running_mode' =>
'server',
106 'allow_cancel' => FALSE,
112 'name' => translate(
'sch_hipo_replacing_asset_attributes'),
113 'function_call' => Array(
114 'process_function' =>
'processAttributes',
116 'running_mode' =>
'server',
117 'skip_step' => FALSE,
119 'allow_cancel' => TRUE,
125 'name' => translate(
'sch_hipo_replacing_asset_contents'),
126 'function_call' => Array(
127 'process_function' =>
'processContent',
129 'running_mode' =>
'server',
130 'skip_step' => FALSE,
132 'allow_cancel' => TRUE,
138 'name' => translate(
'sch_hipo_replacing_asset_metadata'),
139 'function_call' => Array(
140 'process_function' =>
'processMetadata',
142 'running_mode' =>
'server',
143 'skip_step' => FALSE,
145 'allow_cancel' => TRUE,
151 'name' => translate(
'sch_hipo_replacing_schema_values'),
152 'function_call' => Array(
153 'process_function' =>
'processSchemas',
155 'running_mode' =>
'server',
156 'skip_step' => FALSE,
158 'allow_cancel' => TRUE,
164 'name' => translate(
'hipo_releasing_locks'),
165 'function_call' => Array(
166 'process_function' =>
'releaseLocks',
168 'running_mode' =>
'server',
170 'skip_step' => FALSE,
171 'allow_cancel' => FALSE,
177 'name' => translate(
'sch_hipo_regenerating_metadata'),
179 'init_details_function' =>
'getRegenerateMetadataDetails',
181 'running_mode' =>
'server',
183 'allow_cancel' => FALSE,
189 'name' => translate(
'sch_hipo_reindexing_assets'),
191 'init_details_function' =>
'getReindexAssetDetails',
193 'running_mode' =>
'server',
195 'allow_cancel' => FALSE,
213 if (array_key_exists(
'contextid', $this->_running_vars) === FALSE) {
214 trigger_localised_error(
'SCH0031', E_USER_WARNING);
218 return parent::prepare();
235 $job_type =
'hipo_job_acquire_locks';
237 $options[
'auto_complete'] = TRUE;
239 $running_vars = Array(
240 'assetids' => array_keys($this->_running_vars[
'search_data']),
241 'lock_type' => Array(
'all'),
242 'forceably_acquire' => FALSE,
243 'dependants_only' => TRUE,
261 $job_type =
'hipo_job_regenerate_metadata';
263 $options[
'auto_complete'] = TRUE;
265 $running_vars = Array(
266 'schemaids' => $this->_running_vars[
'schemaids'],
267 'contextids' => Array($this->_running_vars[
'contextid']),
286 $job_type =
'hipo_job_reindex';
288 $options[
'auto_complete'] = TRUE;
290 $running_vars = Array(
291 'root_assetid' => array_keys($this->_running_vars[
'search_data']),
292 'contextid' => $this->_running_vars[
'contextid'],
297 'job_dir' => SQ_PACKAGES_PATH.
'/search/hipo_jobs',
314 if (!isset($this->_running_vars[
're_lock_assets'])) {
315 $this->_running_vars[
're_lock_assets'] = array_keys($this->_running_vars[
'search_data']);
318 $assetid = array_shift($this->_running_vars[
're_lock_assets']);
319 unset($this->_running_vars[
're_lock_assets'][$assetid]);
321 $children = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
323 foreach ($children as $dep_child_id => $dep_child_type_code) {
324 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($dep_child_id,
'all');
327 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
329 $step_data[
'message'] = translate(
'sch_tool_global_sr_releasing_locks', $asset_info[$assetid][
'name']);
331 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'all');
333 $this->_running_vars[
'done_assetids'][] = $assetid;
335 if (empty($this->_running_vars[
're_lock_assets'])) {
336 unset($this->_running_vars[
'done_assetids']);
337 $step_data[
'percent_done'] = 100;
338 $step_data[
'complete'] = TRUE;
340 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / count(array_keys($this->_running_vars[
'search_data']))) * 100;
341 $step_data[
'complete'] = FALSE;
357 $search_count = Array();
358 $search_string = preg_replace(
'/([\.\\\!\+\*\?\[\]\^\$\(\)\=\!<>\|\:\/]+)/i',
'\\\${1}', $this->_running_vars[
'search_string']);
360 foreach ($this->_running_vars[
'search_data'] as $assetid => $contents) {
361 $search_count[$assetid] = 0;
363 foreach (Array(
'attributes',
'contents',
'metadata',
'schema') as $type) {
364 if (isset($contents[$type])) {
366 foreach ($contents[$type] as $index => $value) {
368 if ($type ==
'metadata' || $type ==
'schema') {
369 $value = $value[
'value'];
373 preg_match_all(
"/$search_string/i", $value, $matches);
374 $search_count[$assetid] += count($matches[0]);
375 $cvrd_sch_str = htmlentities($search_string);
376 if ($cvrd_sch_str != $search_string) {
378 preg_match_all(
'/'.$cvrd_sch_str.
'/i', $value, $matches);
379 $search_count[$assetid] += count($matches[0]);
387 return $search_count;
405 $GLOBALS[
'SQ_SYSTEM']->changeContext($this->_running_vars[
'contextid']);
410 $o->openSection(translate(
'sch_tool_global_sr_confirmation'));
411 $o->openField(
'',
'replace_selection');
414 <script type=
"text/javascript" src=
"<?php echo sq_web_path('data'); ?>/asset_types/tool_search_replace/js/search_and_replace.js"></script>
416 <style type=
"text/css">
417 @
import url(<?php echo sq_web_path(
'data'); ?>/asset_types/tool_search_replace/css/search_and_replace.css);
418 table.expandable thead th {
419 background-image: url(<?php echo sq_web_path(
'lib'); ?>/web/images/icons/expand_arrow.gif);
421 table thead th.match-checkbox, table thead th.all-asset-checkbox {
422 background-image: none;
425 <p style=
"text-align: center">
426 <span
class=
"link" id=
"select-deselect-link-top" onclick=
"setAllCheckboxes(this)"><?php echo translate(
'sch_tool_global_sr_select_all'); ?></span> |
427 <span
class=
"link" id=
"expand-collapse-link-top" onclick=
"toggleAllTbodyDisplays(this)" ><?php echo translate(
'sch_tool_global_sr_expand_all'); ?></span>
430 <div
id=
"confirmations-container">
433 $names = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($this->_running_vars[
'search_data']),
'', FALSE,
'name');
434 foreach ($this->_running_vars[
'search_data'] as $assetid => $value) {
436 <table
class=
"sq-backend-table expandable" style=
"margin-bottom: 10px">
439 <th onclick=
"toggleTBodyDisplay(this)">
440 <?php echo get_asset_tag_line($assetid); ?>
441 - <?php echo translate(
'sch_tool_global_sr_file_match(es)', $search_count[$assetid]); ?>
443 <th
class=
"all-asset-checkbox">
444 <?php check_box($prefix.
'_asset_'.$assetid.
'_all', 1, FALSE,
'toggleTBodyCheckboxes(this)'); ?>
448 <tbody style=
"display: none">
453 if (!empty($value[
'attributes'])) {
458 if (!empty($value[
'metadata'])) {
463 if (isset($value[
'contents'])) {
468 if (isset($value[
'schema'])) {
482 <p style=
"text-align: center">
483 <span
class=
"link" id=
"select-deselect-link-bottom" onclick=
"setAllCheckboxes(this)"><?php echo translate(
'sch_tool_global_sr_select_all'); ?></span> |
484 <span
class=
"link" id=
"expand-collapse-link-bottom" onclick=
"toggleAllTbodyDisplays(this)" ><?php echo translate(
'sch_tool_global_sr_expand_all'); ?></span>
488 $o->addHiddenField(
'form_submitted', 1);
492 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
510 if (!isset($_REQUEST[
'form_submitted'])) {
517 if (empty($this->_running_vars[
'search_data'])) {
527 $this->_running_vars[
'attribute_replacements_total'] = 0;
528 $this->_running_vars[
'content_replacements_total'] = 0;
529 $this->_running_vars[
'metadata_replacements_total'] = 0;
530 $this->_running_vars[
'schema_replacements_total'] = 0;
532 foreach ($this->_running_vars[
'search_data'] as $assetid => $value) {
533 if (isset($value[
'attributes'])) {
534 $this->_running_vars[
'attribute_replacements'][$assetid] = $value[
'attributes'];
535 $this->_running_vars[
'attribute_replacements_total']++;
537 if (isset($value[
'contents'])) {
538 $this->_running_vars[
'content_replacements'][$assetid] = $value[
'contents'];
539 $this->_running_vars[
'content_replacements_total']++;
541 if (isset($value[
'metadata'])) {
542 $this->_running_vars[
'metadata_replacements'][$assetid] = $value[
'metadata'];
543 $this->_running_vars[
'metadata_replacements_total']++;
545 if (isset($value[
'schema'])) {
546 $this->_running_vars[
'schema_replacements'][$assetid] = $value[
'schema'];
547 $this->_running_vars[
'schema_replacements_total']++;
548 $this->_running_vars[
'schemaids'][] = $assetid;
551 if ($this->_running_vars[
'attribute_replacements_total'] == 0) {
554 if ($this->_running_vars[
'content_replacements_total'] == 0) {
557 if ($this->_running_vars[
'metadata_replacements_total'] == 0) {
560 if ($this->_running_vars[
'schema_replacements_total'] == 0) {
566 $step_data[
'percent_done'] = 100;
567 $step_data[
'complete'] = TRUE;
587 <table
class=
"sq-backend-table expandable component" border=
"1">
590 <th colspan=
"2" onclick=
"toggleTBodyDisplay(this)">
591 <?php echo translate(
'asset_attributes'); ?>
593 <th style=
"text-align: right" class=
"match-checkbox">
594 <?php check_box($prefix.
'_asset_'.$assetid.
'_attr_all', 1, FALSE,
'toggleTBodyCheckboxes(this); updateParentCheckboxes(this);',
'class="component-checkbox"'); ?>
599 <tbody style=
"display: none">
601 <th style=
"width: 30%"><?php echo translate(
'attribute_name'); ?></th>
602 <th><?php echo translate(
'match'); ?></th>
603 <th
class=
"match-checkbox"> </th>
606 foreach ($attr_matches as $attr_name => $attr_details) {
607 foreach ($attr_details[
'matches'] as $offset) {
608 $html_id = $prefix.
'_asset_'.$assetid.
'_attr_'.$attr_name.
'_'.$offset;
611 <td><?php echo $attr_name; ?></th>
612 <td><label
for=
"<?php echo $html_id; ?>"><?php $this->
_printHighlightedMatch($this->_running_vars[
'search_string'], $attr_details[
'value'], $offset); ?></label></td>
613 <td
class=
"match-checkbox"><?php check_box($html_id, 1, FALSE,
'updateParentCheckboxes(this)'); ?></td>
639 <table
class=
"sq-backend-table expandable component" border=
"1">
642 <th colspan=
"3" onclick=
"toggleTBodyDisplay(this)">
643 <?php echo translate(
'asset_metadata'); ?>
645 <th
class=
"match-checkbox" style=
"text-align: right">
646 <?php check_box($prefix.
'_asset_'.$assetid.
'_attr_all', 1, FALSE,
'toggleTBodyCheckboxes(this); updateParentCheckboxes(this);',
'class="component-checkbox"'); ?>
650 <tbody style=
"display: none">
652 <th><?php echo translate(
'field_id'); ?></th>
653 <th><?php echo translate(
'match'); ?></th>
657 foreach ($meta_matches as $field_id => $field_details) {
658 foreach ($field_details[
'matches'] as $offset) {
659 $html_id = $prefix.
'_asset_'.$assetid.
'_metadata_'.$field_id.
'_'.$offset;
662 <td><?php echo get_asset_tag_line($field_id); ?></th>
663 <td><?php echo $field_details[
'name']; ?></td>
664 <td><label
for=
"<?php echo $html_id; ?>"><?php $this->
_printHighlightedMatch($this->_running_vars[
'search_string'], $field_details[
'value'], $offset); ?></label></td>
665 <td
class=
"match-checkbox"><?php check_box($html_id, 1, FALSE,
'updateParentCheckboxes(this)'); ?></td>
691 <table
class=
"sq-backend-table expandable component" border=
"1">
694 <th colspan=
"2" onclick=
"toggleTBodyDisplay(this)">
695 <?php echo translate(
'metadata_schema'); ?>
697 <th
class=
"match-checkbox" style=
"text-align: right">
698 <?php check_box($prefix.
'_asset_'.$assetid.
'_attr_all', 1, FALSE,
'toggleTBodyCheckboxes(this); updateParentCheckboxes(this);',
'class="component-checkbox"'); ?>
702 <tbody style=
"display: none">
704 <th><?php echo translate(
'field_id'); ?></th>
705 <th><?php echo translate(
'match'); ?></th>
709 foreach ($schema_matches as $field_id => $schema_details) {
710 foreach ($schema_details[
'matches'] as $offset) {
711 $html_id = $prefix.
'_asset_'.$assetid.
'_schemafield_'.$field_id.
'_'.$offset;
714 <td><?php echo get_asset_tag_line($field_id); ?></th>
715 <td><label
for=
"<?php echo $html_id; ?>"><?php $this->
_printHighlightedMatch($this->_running_vars[
'search_string'], $schema_details[
'value'], $offset); ?></label></td>
716 <td
class=
"match-checkbox"><?php check_box($html_id, 1, FALSE,
'updateParentCheckboxes(this)'); ?></td>
742 <table
class=
"sq-backend-table expandable component" border=
"1">
745 <th colspan=
"2" onclick=
"toggleTBodyDisplay(this)">
746 <?php echo translate(
'asset_contents'); ?>
748 <th
class=
"match-checkbox" style=
"text-align: right">
749 <?php check_box($prefix.
'_asset_'.$assetid.
'_content_all', 1, FALSE,
'toggleTBodyCheckboxes(this); updateParentCheckboxes(this);',
'class="component-checkbox"'); ?>
753 <tbody style=
"display: none">
755 <th><?php echo translate(
'div_id'); ?></th>
756 <th><?php echo translate(
'match'); ?></th>
760 foreach ($div_matches as $div_id => $div_details) {
761 foreach ($div_details[
'matches'] as $offset) {
762 $html_id = $prefix.
'_asset_'.$assetid.
'_content_'.$div_id.
'_'.$offset;
765 <td><?php echo $div_id; ?></th>
766 <td><label
for=
"<?php echo $html_id; ?>"><?php $this->
_printHighlightedMatch($this->_running_vars[
'search_string'], $div_details[
'value'], $offset); ?></label></td>
767 <td
class=
"match-checkbox"><?php check_box($html_id, 1, FALSE,
'updateParentCheckboxes(this)'); ?></td>
791 $GLOBALS[
'SQ_SYSTEM']->changeContext($this->_running_vars[
'contextid']);
793 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
794 $search_string = $this->_running_vars[
'search_string'];
795 $replace_string = $this->_running_vars[
'replace_string'];
796 $assetid = key($this->_running_vars[
'content_replacements']);
797 $match_case = $this->_running_vars[
'match_case'];
798 $asset = $am->getAssetInfo(Array($assetid));
800 $step_data[
'message'] = translate(
'sch_tool_global_sr_replacing_with_in', $search_string, $replace_string, $asset[$assetid][
'name']);
802 $asset_contents = $this->_running_vars[
'search_data'][$assetid][
'contents'];
803 foreach ($asset_contents as $contents_id => $contents_value) {
804 $new_data = $this->
_replaceOccurrences($search_string, $replace_string, $contents_value[
'value'], $contents_value[
'matches'], $match_case);
805 $am->setEditableContents($contents_id, $new_data);
808 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset_contents);
810 unset($this->_running_vars[
'content_replacements'][$assetid]);
812 $this->_running_vars[
'done_assetids'][] = $assetid;
814 if (empty($this->_running_vars[
'content_replacements'])) {
815 unset($this->_running_vars[
'done_assetids']);
816 $step_data[
'percent_done'] = 100;
817 $step_data[
'complete'] = TRUE;
819 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / $this->_running_vars[
'content_replacements_total']) * 100;
820 $step_data[
'complete'] = FALSE;
823 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
841 $GLOBALS[
'SQ_SYSTEM']->changeContext($this->_running_vars[
'contextid']);
843 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
845 $search_string = $this->_running_vars[
'search_string'];
846 $replace_string = $this->_running_vars[
'replace_string'];
847 $assetid = key($this->_running_vars[
'schema_replacements']);
848 $match_case = $this->_running_vars[
'match_case'];
849 $asset = $am->getAssetInfo(Array($assetid));
851 $step_data[
'message'] = translate(
'sch_tool_global_sr_replacing_with_in', $search_string, $replace_string, $asset[$assetid][
'name']);
853 foreach ($this->_running_vars[
'schema_replacements'][$assetid] as $fieldid => $data) {
854 $new_data = $this->
_replaceOccurrences($search_string, $replace_string, $data[
'value'], $data[
'matches'], $match_case);
855 $field = $am->getAsset($fieldid);
856 $value_component = Array();
857 $field->decodeValueString($new_data, $default_data, $value_component);
858 $field->setAttrValue(
'default', $default_data);
859 $field->saveAttributes();
860 $am->forgetAsset($field);
863 unset($this->_running_vars[
'schema_replacements'][$assetid]);
865 $this->_running_vars[
'done_assetids'][] = $assetid;
867 if (empty($this->_running_vars[
'schema_replacements'])) {
868 unset($this->_running_vars[
'done_assetids']);
869 $step_data[
'percent_done'] = 100;
870 $step_data[
'complete'] = TRUE;
872 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / $this->_running_vars[
'schema_replacements_total']) * 100;
873 $step_data[
'complete'] = FALSE;
876 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
894 $GLOBALS[
'SQ_SYSTEM']->changeContext($this->_running_vars[
'contextid']);
896 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
898 $search_string = $this->_running_vars[
'search_string'];
899 $replace_string = $this->_running_vars[
'replace_string'];
900 $match_case = $this->_running_vars[
'match_case'];
901 $assetid = key($this->_running_vars[
'attribute_replacements']);
903 $asset = $am->getAsset($assetid);
905 $step_data[
'message'] = translate(
'sch_tool_global_sr_replacing_with_in', $search_string, $replace_string, $asset->name);
907 foreach ($this->_running_vars[
'attribute_replacements'][$assetid] as $attrid => $data) {
908 $new_data = $this->
_replaceOccurrences($search_string, $replace_string, $data[
'value'], $data[
'matches'], $match_case);
909 $asset->setAttrValue($attrid, $new_data);
911 $asset->saveAttributes();
913 $am->forgetAsset($asset);
914 unset($this->_running_vars[
'attribute_replacements'][$assetid]);
916 $this->_running_vars[
'done_assetids'][] = $assetid;
918 if (empty($this->_running_vars[
'attribute_replacements'])) {
919 unset($this->_running_vars[
'done_assetids']);
920 $step_data[
'percent_done'] = 100;
921 $step_data[
'complete'] = TRUE;
923 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / $this->_running_vars[
'attribute_replacements_total']) * 100;
924 $step_data[
'complete'] = FALSE;
927 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
945 $GLOBALS[
'SQ_SYSTEM']->changeContext($this->_running_vars[
'contextid']);
947 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
948 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
950 $search_string = $this->_running_vars[
'search_string'];
951 $replace_string = $this->_running_vars[
'replace_string'];
952 $match_case = $this->_running_vars[
'match_case'];
953 $assetid = key($this->_running_vars[
'metadata_replacements']);
955 $asset = $am->getAssetInfo(Array($assetid));
957 $step_data[
'message'] = translate(
'sch_tool_global_sr_replacing_with_in', $search_string, $replace_string, $asset[$assetid][
'name']);
959 $metadata = $mm->getMetadata($assetid);
961 $regen_all_contexts = FALSE;
962 foreach ($this->_running_vars[
'metadata_replacements'][$assetid] as $fieldid => $data) {
963 $new_data = $this->
_replaceOccurrences($search_string, $replace_string, $data[
'value'], $data[
'matches'], $match_case);
964 $metadata[$fieldid][0][
'value'] = $new_data;
965 $field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($fieldid);
966 if (!$regen_all_contexts && (!$field->attr(
'is_contextable') || $field instanceof
Metadata_Field_Select)) {
967 $regen_all_contexts = TRUE;
971 $mm->setMetadata($assetid, $metadata);
972 if ($regen_all_contexts) {
973 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
974 foreach ($all_contexts as $contextid => $context_data) {
975 $mm->generateContentFile($assetid, FALSE, $contextid);
978 $mm->generateContentFile($assetid);
981 unset($this->_running_vars[
'metadata_replacements'][$assetid]);
983 $this->_running_vars[
'done_assetids'][] = $assetid;
985 if (empty($this->_running_vars[
'metadata_replacements'])) {
986 unset($this->_running_vars[
'done_assetids']);
987 $step_data[
'percent_done'] = 100;
988 $step_data[
'complete'] = TRUE;
990 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / $this->_running_vars[
'metadata_replacements_total']) * 100;
991 $step_data[
'complete'] = FALSE;
994 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
1012 $occurrences = Array();
1014 $needle = strtolower($needle);
1015 $haystack = strtolower($haystack);
1016 $result = strpos($haystack, $needle);
1017 while (FALSE !== $result) {
1018 $occurrences[] = $result;
1019 $offset = $result + strlen($needle);
1020 $result = strpos($haystack, $needle, $offset);
1026 $html_encoded_needle = htmlentities($needle);
1027 if ($needle != $html_encoded_needle) {
1029 $result = strpos($haystack, $html_encoded_needle);
1030 while (FALSE !== $result) {
1031 $occurrences[] = $result;
1032 $offset = $result + strlen($needle);
1033 $result = strpos($haystack, $html_encoded_needle, $offset);
1036 return $occurrences;
1055 if (empty($offsets))
return $haystack;
1056 $search_len = strlen($needle);
1057 $encoded_search_len = strlen(htmlentities($needle));
1060 foreach ($offsets as $id => $offset) {
1061 $encoded = (strtolower(substr($haystack, $offset, $search_len)) != strtolower($needle));
1062 $this_search_len = $encoded ? $encoded_search_len : $search_len;
1063 $rep_str = $new_needle;
1065 $rep_str = $this->
_matchCapitals(substr($haystack, $offset, $this_search_len), $new_needle);
1067 $result_str .= substr($haystack, $last_offset, $offset - $last_offset).$rep_str;
1068 $last_offset = $offset + $this_search_len;
1070 $result_str .= substr($haystack, $last_offset);
1087 $ret_str = $student;
1088 if (strtoupper($teacher) == $teacher) {
1089 $ret_str = strtoupper($student);
1090 }
else if (strtoupper($teacher[0]) == $teacher[0]) {
1091 $ret_str[0] = strtoupper($ret_str[0]);
1092 }
else if (strtolower($teacher[0]) == $teacher[0]) {
1093 $ret_str[0] = strtolower($ret_str[0]);
1112 foreach ($occ as $id => $offset) {
1113 echo
'<tr><td><input type="checkbox" /></td><td>';
1133 if (substr($haystack, $offset, strlen($needle)) != $needle) {
1134 $needle = htmlentities($needle);
1137 $forward_limit = $this->_findForwardbreak($haystack, $offset + strlen($needle));
1138 echo htmlentities(ltrim(substr($haystack, $back_limit, $offset - $back_limit),
'\n\r'));
1139 echo
'<span style="background:yellow">'.$needle.
'</span>';
1140 echo htmlentities(rtrim(substr($haystack, $offset + strlen($needle), $forward_limit - ($offset + strlen($needle)))));
1158 while ($ret > $offset - 200 && $ret > 0) {
1159 if ($haystack[$ret] ==
'>') {
1161 }
else if ($haystack[$ret] ==
'<') {
1166 if ($ret == 0)
return $ret;
1168 $oldspace = $ret - $limit;
1169 while ($ret > $offset - $limit && $ret > 0) {
1170 switch ($haystack[$ret]) {
1202 while (($end_tag < $offset + 200) && ($end_tag < strlen($haystack))) {
1203 if ($haystack[$end_tag] ==
'<') {
1205 }
else if ($haystack[$end_tag] ==
'>') {
1212 $oldspace = $offset + $limit;
1213 while (($ret < $offset + $limit) && ($ret < strlen($haystack))) {
1214 switch ($haystack[$ret]) {
1226 $oldspace = $ret + 1;
1231 if ($end_tag > $oldspace)
return $end_tag;
1245 foreach ($this->_running_vars[
'search_data'] as $assetid => $details) {
1246 if (isset($details[
'attributes'])) {
1247 foreach ($details[
'attributes'] as $attr_name => $attr_val) {
1248 $this->_running_vars[
'search_data'][$assetid][
'attributes'][$attr_name] = Array(
'value' => $attr_val);
1249 $this->_running_vars[
'search_data'][$assetid][
'attributes'][$attr_name][
'matches'] = $this->
_getOccurrences($this->_running_vars[
'search_string'], $attr_val);
1252 if (isset($details[
'contents'])) {
1253 foreach ($details[
'contents'] as $div_id => $div_cont) {
1254 $this->_running_vars[
'search_data'][$assetid][
'contents'][$div_id] = Array(
'value' => $div_cont);
1255 $this->_running_vars[
'search_data'][$assetid][
'contents'][$div_id][
'matches'] = $this->
_getOccurrences($this->_running_vars[
'search_string'], $div_cont);
1258 if (isset($details[
'metadata'])) {
1259 foreach ($details[
'metadata'] as $schema_id => $schema_details) {
1260 $this->_running_vars[
'search_data'][$assetid][
'metadata'][$schema_id][
'matches'] = $this->
_getOccurrences($this->_running_vars[
'search_string'], $schema_details[
'value']);
1263 if (isset($details[
'schema'])) {
1264 foreach ($details[
'schema'] as $schema_id => $schema_details) {
1265 $this->_running_vars[
'search_data'][$assetid][
'schema'][$schema_id][
'matches'] = $this->
_getOccurrences($this->_running_vars[
'search_string'], $schema_details[
'value']);
1283 foreach ($this->_running_vars[
'search_data'] as $assetid => $values) {
1285 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_all'])) {
1286 if (isset($this->_running_vars[
'search_data'][$assetid][
'attributes'])) {
1287 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_attr_all'])) {
1288 foreach ($this->_running_vars[
'search_data'][$assetid][
'attributes'] as $attr_name => $attr_details) {
1289 foreach ($attr_details[
'matches'] as $m) {
1290 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_attr_'.$attr_name.
'_'.$m])) {
1291 $i = array_search($m, $this->_running_vars[
'search_data'][$assetid][
'attributes'][$attr_name][
'matches']);
1292 unset($this->_running_vars[
'search_data'][$assetid][
'attributes'][$attr_name][
'matches'][$i]);
1295 if (empty($this->_running_vars[
'search_data'][$assetid][
'attributes'][$attr_name][
'matches'])) {
1296 unset($this->_running_vars[
'search_data'][$assetid][
'attributes'][$attr_name]);
1299 if (empty($this->_running_vars[
'search_data'][$assetid][
'attributes'])) {
1300 unset($this->_running_vars[
'search_data'][$assetid][
'attributes']);
1305 if (isset($this->_running_vars[
'search_data'][$assetid][
'contents'])) {
1306 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_content_all'])) {
1307 foreach ($this->_running_vars[
'search_data'][$assetid][
'contents'] as $div_id => $div_details) {
1308 foreach ($div_details[
'matches'] as $m) {
1309 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_content_'.$div_id.
'_'.$m])) {
1310 $i = array_search($m, $this->_running_vars[
'search_data'][$assetid][
'contents'][$div_id][
'matches']);
1311 unset($this->_running_vars[
'search_data'][$assetid][
'contents'][$div_id][
'matches'][$i]);
1314 if (empty($this->_running_vars[
'search_data'][$assetid][
'contents'][$div_id][
'matches'])) {
1315 unset($this->_running_vars[
'search_data'][$assetid][
'contents'][$div_id]);
1318 if (empty($this->_running_vars[
'search_data'][$assetid][
'contents'])) {
1319 unset($this->_running_vars[
'search_data'][$assetid][
'contents']);
1324 if (isset($this->_running_vars[
'search_data'][$assetid][
'metadata'])) {
1325 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_metadata_all'])) {
1326 foreach ($this->_running_vars[
'search_data'][$assetid][
'metadata'] as $field_id => $field_details) {
1327 foreach ($field_details[
'matches'] as $m) {
1328 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_metadata_'.$field_id.
'_'.$m])) {
1329 $i = array_search($m, $this->_running_vars[
'search_data'][$assetid][
'metadata'][$field_id][
'matches']);
1330 unset($this->_running_vars[
'search_data'][$assetid][
'metadata'][$field_id][
'matches'][$i]);
1333 if (empty($this->_running_vars[
'search_data'][$assetid][
'metadata'][$field_id][
'matches'])) {
1334 unset($this->_running_vars[
'search_data'][$assetid][
'metadata'][$field_id]);
1337 if (empty($this->_running_vars[
'search_data'][$assetid][
'metadata'])) {
1338 unset($this->_running_vars[
'search_data'][$assetid][
'metadata']);
1343 if (isset($this->_running_vars[
'search_data'][$assetid][
'schema'])) {
1344 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_schema_all'])) {
1345 foreach ($this->_running_vars[
'search_data'][$assetid][
'schema'] as $field_id => $field_details) {
1346 foreach ($field_details[
'matches'] as $m) {
1347 if (!isset($_REQUEST[$prefix.
'_asset_'.$assetid.
'_schemafield_'.$field_id.
'_'.$m])) {
1348 $i = array_search($m, $this->_running_vars[
'search_data'][$assetid][
'schema'][$field_id][
'matches']);
1349 unset($this->_running_vars[
'search_data'][$assetid][
'schema'][$field_id][
'matches'][$i]);
1352 if (empty($this->_running_vars[
'search_data'][$assetid][
'schema'][$field_id][
'matches'])) {
1353 unset($this->_running_vars[
'search_data'][$assetid][
'schema'][$field_id]);
1356 if (empty($this->_running_vars[
'search_data'][$assetid][
'schema'])) {
1357 unset($this->_running_vars[
'search_data'][$assetid][
'schema']);
1362 if (empty($this->_running_vars[
'search_data'][$assetid])) {
1363 unset($this->_running_vars[
'search_data'][$assetid]);