purl_path.inc in Persistent URL 6
File
includes/purl_path.inc
View source
<?php
class purl_path implements purl_processor {
public function method() {
return 'path';
}
public function admin_form(&$form, $id) {
}
public function detect($q) {
return $q;
}
public function description() {
return t('Choose a path. May contain only lowercase letters, numbers, dashes and underscores. e.g. "my-value"');
}
public function parse($valid_values, $q) {
$parsed = array();
$args = explode('/', $q);
$arg = current($args);
while (isset($valid_values[$arg])) {
$parsed[$arg] = $valid_values[$arg];
array_shift($args);
$arg = current($args);
if (in_array($arg, $parsed)) {
break;
}
}
return purl_path_elements($this, $parsed);
}
public function adjust(&$value, $item, &$q) {
$q = $this
->remove($q, $item);
$value = $this
->remove($value, $item);
}
public function remove($q, $element) {
$args = explode('/', $q);
if (current($args) === (string) $element->value) {
array_shift($args);
}
return implode('/', $args);
}
public function rewrite(&$path, &$options, $element) {
$alt = $this
->remove($path, $element);
if ($alt == $path && !_purl_skip($element, $options)) {
$items = empty($path) ? array() : explode('/', $path);
array_unshift($items, $element->value);
$path = implode('/', $items);
}
}
}