You are here

class purl_extension in Persistent URL 6

Same name and namespace in other branches
  1. 7 includes/purl_extension.inc \purl_extension

File extension style. Like ".csv"

Hierarchy

Expanded class hierarchy of purl_extension

1 string reference to 'purl_extension'
purl_purl_processor in ./purl.module
Implementation of hook_purl_processor().

File

includes/purl_extension.inc, line 6

View source
class purl_extension implements purl_processor {
  public function admin_form(&$form, $id) {
  }
  public function detect($q) {
    $last = explode('.', array_pop(explode('/', $q)));
    if (count($last) > 1) {
      return array_pop($last);
    }
    return '';
  }
  public function method() {
    return 'extension';
  }
  public function description() {
    return t('Enter a extension for this context, such as "csv".');
  }
  public function parse($valid_values, $q) {
    $parsed = array();
    if (isset($valid_values[$q])) {
      $parsed[$q] = $valid_values[$q];
    }
    return purl_path_elements($this, $parsed);
  }

  /**
   * Rewrite the query string. Note that this is being passed through
   * the custom_url_rewrite_inbound() stack and may *not* directly
   * affect $_GET['q']. See purl_init() for how $_GET['q'] is affected
   * by processors.
   */
  public function adjust(&$value, $item, &$q) {
    $q = $this
      ->remove($q, $item);
    $value = $this
      ->remove($value, $item);
  }

  /**
   * Remove our extension from the tail end of the path.
   *
   * @param $q
   *   The current path.
   * @param $element
   *   a purl_path_element object
   * @return path string with the extension removed.
   */
  public function remove($q, $element) {
    $args = explode('.', $q);
    if (count($args > 1)) {
      $extension = array_pop($args);
      if ($element->value == $extension) {
        return implode('.', $args);
      }
    }
    return $q;
  }

  /**
   * Because of the expected usage of the files extensions we don't provide
   * a rewrite.
   */
  public function rewrite(&$path, &$options, $element) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
purl_extension::adjust public function Rewrite the query string. Note that this is being passed through the custom_url_rewrite_inbound() stack and may *not* directly affect $_GET['q']. See purl_init() for how $_GET['q'] is affected by processors. Overrides purl_processor::adjust
purl_extension::admin_form public function Allow extension of the admin setup form. Overrides purl_processor::admin_form
purl_extension::description public function Provide a description of processor for the end user Overrides purl_processor::description
purl_extension::detect public function Detect the the processor value for the current page request Overrides purl_processor::detect
purl_extension::method public function Return the method the processor users. Overrides purl_processor::method
purl_extension::parse public function Detects processor in the passed 'value'. Overrides purl_processor::parse
purl_extension::remove public function Remove our extension from the tail end of the path.
purl_extension::rewrite public function Because of the expected usage of the files extensions we don't provide a rewrite. Overrides purl_processor::rewrite