17 require_once SQ_INCLUDE_PATH.
'/asset_attribute.inc';
18 require_once dirname(dirname(__FILE__)).
'/serialise/serialise.inc';
20 define(
'SQ_PARAM_MAP_DEFAULT_ATTRIBUTE',
'assetid');
21 define(
'SQ_PARAM_MAP_ATTR_OPTION_KEYWORD',
'keyword');
22 define(
'SQ_PARAM_MAP_DEFAULT_KEYWORD',
'asset_assetid');
68 if (!isset($this->_params[
'parameters'])) {
69 $this->_params[
'parameters'] = Array();
71 if ($value == NULL) $value = Array();
90 $this->_params[
'parameters'][$code] = $label;
106 if (!isset($this->_params[
'parameters'][$old_code])) {
110 if (isset($this->_params[
'parameters'][$new_code])) {
111 trigger_error(
'Cannot Rename Parameter. Code conflict.', E_USER_WARNING);
116 $this->_params[
'parameters'][$new_code] = $this->_params[
'parameters'][$old_code];
117 unset($this->_params[
'parameters'][$old_code]);
119 $value = unserialize($this->value);
120 if (isset($value[$old_code])) {
121 $value[$new_code] = $value[$old_code];
122 unset($value[$old_code]);
123 $this->value = serialize($value);
139 $value = unserialize($this->value);
140 unset($this->_params[
'parameters'][$code]);
141 unset($value[$code]);
142 $this->value = serialize($value);
143 $this->processed = $this->
setValue($value);
157 function paint($prefix, $read_only=FALSE)
159 $value = @unserialize($this->value);
163 <table border=
"0" cellpadding=
"0" cellspacing=
"0" class=
"sq-backend-table">
165 <th><?php echo translate(
'parameter'); ?></th>
166 <th><?php echo translate(
'source'); ?></th>
171 if (!empty($value)) {
172 foreach ($value as $parameter => $sources) {
175 <td><?php echo $this->_params[
'parameters'][$parameter]; ?></td>
177 <table border=
"0" cellpadding=
"5" cellspacing=
"0" class=
"sq-backend-table">
179 foreach ($sources as $index => $details) {
180 $source_type = $details[
'source'];
181 if (!isset($source_types[$source_type]))
continue;
183 $one_source_prefix = $prefix.
'['.$parameter.
']['.$index.
']';
186 <td style=
"width:30ex"><strong><?php echo $source_types[$source_type]; ?></strong></td>
188 <td style=
"text-align:right">
191 check_box($one_source_prefix.
'[delete]');
192 echo
'<label for="'.$one_source_prefix.
'[delete]">'.translate(
'delete').
'</label>';
232 combo_box($prefix.
'[source]', $this->_getSourceTypes(), FALSE, Array());
249 $source_type = array_get_index($data,
'source');
252 hidden_field($prefix.
'[source]', $source_type);
255 switch ($source_type) {
259 $attribute = array_get_index($data,
'attribute', SQ_PARAM_MAP_DEFAULT_ATTRIBUTE);
260 $keyword = array_get_index($data,
'keyword', SQ_PARAM_MAP_DEFAULT_KEYWORD);
262 if (is_null($attribute)) {
263 echo translate(
'not_configured');
266 if ($attribute == SQ_PARAM_MAP_ATTR_OPTION_KEYWORD) {
267 echo
' - '.(empty($keyword) ? translate(
'not_configured') : $keyword);
272 'assetid' => translate(
'asset_id'),
273 SQ_PARAM_MAP_ATTR_OPTION_KEYWORD => translate(
'keyword'),
275 combo_box($prefix.
'[attribute]', $options, FALSE, $attribute, 0,
'onchange="document.getElementById(\''.$prefix.
'[keyword]\').style.visibility = (this.value == \'keyword\') ? \'\' : \'hidden\'"');
276 text_box($prefix.
'[keyword]', $keyword,
'',
'', FALSE, ($attribute == SQ_PARAM_MAP_ATTR_OPTION_KEYWORD) ?
'' :
'style="visibility: hidden"');
281 $value = array_get_index($data,
'value');
283 if (is_null($value)) {
284 echo translate(
'not_configured');
286 echo htmlspecialchars($value);
289 text_box($prefix.
'[value]', $value);
294 $value = array_get_index($data,
'index');
296 if (is_null($value)) {
297 echo translate(
'not_configured');
302 text_box($prefix.
'[index]', $value);
321 combo_box($prefix.
'[parameter]', Array(
''=>
'-- '.translate(
'new_mapping').
' --')+$this->_params[
'parameters'], FALSE, Array());
337 if (isset($_POST[$prefix]) && is_array($_POST[$prefix])) {
338 foreach ($_POST[$prefix] as $index => $details) {
339 if ($index ==
'new')
continue;
340 $value[$index] = $details;
341 foreach ($details as $j => $fields) {
342 if (in_array($fields[
'source'], Array(
'ASSET',
'USER',
'CURRENT_SITE'))) {
343 unset($value[$index][$j][
'index']);
346 if (array_get_index($value[$index][$j],
'attribute',
'') == SQ_PARAM_MAP_ATTR_OPTION_KEYWORD) {
347 $value[$index][$j][
'keyword'] = preg_replace(
'/(^%|%$)/',
'', trim(array_get_index($value[$index][$j],
'keyword',
'')));
348 if (empty($value[$index][$j][
'keyword'])) {
349 $value[$index][$j][
'keyword'] = SQ_PARAM_MAP_DEFAULT_KEYWORD;
353 unset($value[$index][$j][
'keyword']);
354 unset($value[$index][$j][
'attribute']);
357 if (isset($fields[
'delete'])) {
358 unset($value[$index][$j]);
359 if (empty($value[$index])) unset($value[$index]);
365 foreach ($_POST[$prefix][
'new'] as $new_mapping) {
366 if (empty($new_mapping[
'parameter']))
continue;
368 $param = $new_mapping[
'parameter'];
369 unset($new_mapping[
'parameter']);
371 $value[$param][] = $new_mapping;
376 $this->processed = $this->
setValue($value);
394 $value = unserialize($this->value);
396 if (!isset($value[$parameter]))
return NULL;
397 foreach ($value[$parameter] as $rule) {
398 switch ($rule[
'source']) {
400 if (!empty($rule[
'index']) && isset($_GET[$rule[
'index']])) {
401 return $_GET[$rule[
'index']];
406 if (!empty($rule[
'index']) && isset($_POST[$rule[
'index']])) {
407 return $_POST[$rule[
'index']];
414 if (!empty($rule[
'index']) && isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][$rule[
'index']])) {
415 return $_SESSION[SQ_SESSION_SANDBOX_INDEX][$rule[
'index']];
420 if (isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][$rule[
'index']]) && (!empty($_SESSION[SQ_SESSION_SANDBOX_INDEX][$rule[
'index']]))) {
421 return $_SESSION[SQ_SESSION_SANDBOX_INDEX][$rule[
'index']];
422 }
else if (isset($_POST[$rule[
'index']]) && (!empty($_POST[$rule[
'index']]))) {
423 return $_POST[$rule[
'index']];
424 }
else if (isset($_GET[$rule[
'index']]) && (!empty($_GET[$rule[
'index']]))) {
425 return $_GET[$rule[
'index']];
432 if (isset($rule[
'value'])) {
433 return replace_global_keywords($rule[
'value']);
441 if (empty($assetid))
return NULL;
442 switch (array_get_index($rule,
'attribute')) {
443 case SQ_PARAM_MAP_ATTR_OPTION_KEYWORD:
444 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
445 if (!empty($asset)) {
446 $keyword = array_get_index($rule,
'keyword',
'');
448 if ($keyword ==
'') {
449 $keyword = SQ_PARAM_MAP_DEFAULT_KEYWORD;
451 return $asset->getKeywordReplacement($keyword);
486 return $_REQUEST[
'limbo_assetid'];
488 if (isset($GLOBALS[
'SQ_SYSTEM']->frontend_asset->id) && !empty($GLOBALS[
'SQ_SYSTEM']->frontend_asset->id)) {
489 return $GLOBALS[
'SQ_SYSTEM']->frontend_asset->id;
491 $curr_asset = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'CURRENT_ASSET', NULL);
492 if (!is_null($curr_asset))
return $curr_asset->id;
499 return $GLOBALS[
'SQ_SYSTEM']->currentUserId();
503 $current_site_id = NULL;
504 if ($GLOBALS[
'SQ_SYSTEM']->isGlobalDefineSet(
'CURRENT_SITE')) {
505 $current_site_id = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'CURRENT_SITE')->id;
507 if ($GLOBALS[
'SQ_SYSTEM']->isGlobalDefineSet(
'CURRENT_ASSET')) {
508 $asset_url = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'CURRENT_ASSET')->getURL();
509 $protocol_pos = strpos($asset_url,
'://');
510 if ($protocol_pos !== FALSE) {
511 $asset_url = substr($asset_url, $protocol_pos + 3);
514 $asset_url = current_url(FALSE, TRUE);
516 $asset_lineage = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromURL(NULL, $asset_url);
517 if (isset($asset_lineage[0])) {
518 $current_site_id = $asset_lineage[0][
'assetid'];
521 return $current_site_id;
537 return array_keys(unserialize($this->value));
555 'GET' =>
'GET '.translate(
'variable_name'),
556 'POST' =>
'POST '.translate(
'variable_name'),
557 'SESSION' =>
'SESSION '.translate(
'variable_name'),
558 'ASSET' => translate(
'current_asset'),
559 'USER' => translate(
'current_user'),
560 'CURRENT_SITE' => translate(
'current_site'),
561 'SET_VALUE' => translate(
'set_value'),
562 'GLOBALS' => translate(
'super_global'),