View source
<?php
class purl_querystring implements purl_processor {
public function method() {
return 'querystring';
}
public function admin_form(&$form, $id) {
$form[$id]['extra']["purl_method_querystring_{$id}_key"] = array(
'#title' => t('Key'),
'#type' => 'textfield',
'#size' => 12,
'#default_value' => variable_get("purl_method_{$id}_key", ''),
'#element_validate' => array(
'purl_admin_form_key_validate',
),
'#provider_id' => $id,
);
}
public function detect($q) {
return drupal_http_build_query(drupal_get_query_parameters($_GET, array(
'q',
'sort',
'order',
'page',
'pass',
)));
}
public function description() {
return t('Choose a querystring. May contain only lowercase letters, numbers, dashes and underscores. e.g. "my-value"');
}
public function parse($valid_values, $qs) {
$elements = array();
parse_str($qs, $elements);
$parsed = array();
foreach ($elements as $k => $v) {
if (isset($valid_values[$k])) {
$parsed[$k] = $valid_values[$k];
$parsed[$k]['id'] = $v;
}
}
return purl_path_elements($this, $parsed);
}
public function adjust(&$value, $item, &$q) {
}
function remove($value, $element) {
$qs = array();
parse_str($value, $qs);
unset($qs[$element->value]);
return drupal_http_build_query($qs);
}
public function rewrite(&$path, &$options, $element) {
if (!_purl_skip($element, $options)) {
$options['query'][$element->value] = $element->id;
}
}
}