You are here

public function link_views_handler_filter_protocol::op_protocol in Link 7

Same name and namespace in other branches
  1. 6.2 views/link_views_handler_filter_protocol.inc \link_views_handler_filter_protocol::op_protocol()
  2. 6 views/link_views_handler_filter_protocol.inc \link_views_handler_filter_protocol::op_protocol()

Filter down the query to include only the selected protocols.

@codingStandardsIgnoreStart

File

views/link_views_handler_filter_protocol.inc, line 105
Contains filter handlers for protocol filters with views.

Class

link_views_handler_filter_protocol
Filter handler for limiting a view to URLs of a certain protocol.

Code

public function op_protocol($field, $upper) {

  // @codingStandardsIgnoreEnd
  $db_type = db_driver();
  $protocols = $this->value;
  $where_conditions = array();
  foreach ($protocols as $protocol) {

    // Simple case, the URL begins with the specified protocol.
    $condition = $field . ' LIKE \'' . $protocol . '%\'';

    // More complex case, no protocol specified but is automatically cleaned
    // up by link_cleanup_url(). RegEx is required for this search operation.
    if ($protocol == 'http') {
      $link_domains = _link_domains();
      if ($db_type == 'pgsql') {

        // PostGreSQL code has NOT been tested. Please report any problems to
        // the link issue queue.
        // pgSQL requires all slashes to be double escaped in regular
        // expressions.
        // @codingStandardsIgnoreLine
        // See http://www.postgresql.org/docs/8.1/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
        $condition .= ' OR ' . $field . ' ~* \'' . '^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $link_domains . '|[a-z][a-z]))' . '\'';
      }
      else {

        // mySQL requires backslashes to be double (triple?) escaped within
        // character classes.
        // @codingStandardsIgnoreLine
        // See http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_regexp
        $condition .= ' OR ' . $field . ' REGEXP \'' . '^(([a-z0-9]([a-z0-9\\\\-_]*\\.)+)(' . $link_domains . '|[a-z][a-z]))' . '\'';
      }
    }
    $where_conditions[] = $condition;
  }
  $this->query
    ->add_where($this->options['group'], implode(' ' . $this->operator . ' ', $where_conditions));
}