You are here

class purl_subdomain in Persistent URL 6

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

Subdomain prefixing.

Hierarchy

Expanded class hierarchy of purl_subdomain

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

File

includes/purl_subdomain.inc, line 6

View source
class purl_subdomain implements purl_processor {
  public function admin_form(&$form, $id) {
    global $base_url;
    $form['purl_location'] = array(
      '#type' => 'fieldset',
    );
    $form['purl_location']['purl_base_domain'] = array(
      '#type' => 'textfield',
      '#title' => t('Default domain'),
      '#description' => t('Enter the default domain if you are using domain modifiers.'),
      '#required' => FALSE,
      '#default_value' => variable_get('purl_base_domain', $base_url),
      '#element_validate' => array(
        'purl_validate_fqdn',
      ),
    );
  }
  function detect($q) {
    $parts = explode('.', str_replace('http://', '', $_SERVER['HTTP_HOST']));
    return count($parts) > 1 ? array_shift($parts) : NULL;
  }
  public function method() {
    return 'subdomain';
  }
  public function description() {
    return t('Enter a sub-domain for this context, such as "mygroup".  Do not include http://');
  }
  public function parse($valid_values, $q) {
    $parsed = array();
    if (isset($valid_values[$q])) {
      $parsed[$q] = $valid_values[$q];
    }
    return purl_path_elements($this, $parsed);
  }
  public function adjust(&$value, $item, &$q) {
    return;
  }
  public function rewrite(&$path, &$options, $element) {
    $options['absolute'] = TRUE;
    if ($base_url = $this
      ->base_url()) {
      if (!_purl_skip($element, $options)) {
        $base = parse_url($base_url);
        $port = !empty($base['port']) ? ':' . $base['port'] : "";
        $options['base_url'] = "{$base['scheme']}://{$element->value}.{$base['host']}{$port}{$base['path']}";
      }
      else {
        $options['base_url'] = $base_url;
      }
    }
  }
  protected function base_url() {
    global $base_url;
    $base = variable_get('purl_base_domain', $base_url);
    return !empty($base) ? $base : $base_url;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
purl_subdomain::adjust public function Used to provide compatibility with the path alias system. Overrides purl_processor::adjust
purl_subdomain::admin_form public function Allow extension of the admin setup form. Overrides purl_processor::admin_form
purl_subdomain::base_url protected function
purl_subdomain::description public function Provide a description of processor for the end user Overrides purl_processor::description
purl_subdomain::detect function Detect the the processor value for the current page request Overrides purl_processor::detect
purl_subdomain::method public function Return the method the processor users. Overrides purl_processor::method
purl_subdomain::parse public function Detects processor in the passed 'value'. Overrides purl_processor::parse
purl_subdomain::rewrite public function Responsible for rewriting outgoing links. Note: it's this functions job to make sure it doesn't alter a link that has already been treated. Overrides purl_processor::rewrite