/**
  * Filter function Strips a URL of certain defined session or tracking params
  *
  * @return string
  */
 static function makeUrlCanonical($url, $event)
 {
     $site_id = $event->getSiteId();
     if (!$site_id) {
         owa_coreAPI::debug('no site_id passed to make makeUrlCanonical. Returning URL as is.');
         return $url;
     }
     // remove port, pass, user, and fragment
     $url = owa_lib::unparseUrl(parse_url($url), array('port', 'user', 'pass', 'fragment'));
     owa_coreAPI::debug('makeUrlCanonical using site_id: ' . $site_id);
     $site = owa_coreAPI::entityFactory('base.site');
     $site->load($site->generateId($site_id));
     $filter_string = $site->getSiteSetting('query_string_filters');
     if ($filter_string) {
         $filters = str_replace(' ', '', $filter_string);
         $filters = explode(',', $filter_string);
     } else {
         $filters = array();
     }
     // merge global filters
     $global_filters = owa_coreAPI::getSetting('base', 'query_string_filters');
     if ($global_filters) {
         $global_filters = str_replace(' ', '', $global_filters);
         $global_filters = explode(',', $global_filters);
         $filters = array_merge($global_filters, $filters);
     }
     // OWA specific params to filter
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'source');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'medium');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'campaign');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'ad');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'ad_type');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'overlay');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'state');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . owa_coreAPI::getSetting('base', 'feed_subscription_param'));
     //print_r($filters);
     // remove jsessionid
     $url = preg_replace('`;jsessionid=[^?]*(?=\\?|$)`i', '', $url);
     // remove matches to URL parameter filter (supporting regular expressions)
     foreach ($filters as $filter => $value) {
         $pattern = '`&' . $value . '(=[^&]*)?(?=&|$)|(?<=\\?)' . $value . '(=[^&]*)?(&|$)`i';
         $url = preg_replace($pattern, '', $url);
     }
     // remove dangling '?'
     $url = rtrim($url, '?');
     //check and remove default page
     $default_page = $site->getSiteSetting('default_page');
     if ($default_page) {
         $default_length = strlen($default_page);
         if ($default_length) {
             //test for string
             $default_test = substr($url, 0 - $default_length, $default_length);
             if ($default_test === $default_page) {
                 $url = substr($url, 0, 0 - $default_length);
             }
         }
     }
     // check and remove trailing slash
     if (substr($url, -1) === '/') {
         $url = substr($url, 0, -1);
     }
     $rewrite_rules_string = $site->getSiteSetting('rewrite_rules');
     if ($rewrite_rules_string) {
         $rewrite_rules_string = trim($rewrite_rules_string);
         if (!empty($rewrite_rules_string)) {
             $rewrite_rule_lines = explode(',', $rewrite_rules_string);
             foreach ($rewrite_rule_lines as $rewrite_rule_line) {
                 $rewrite_rule = explode('->', $rewrite_rule_line, 2);
                 if (count($rewrite_rule) === 2) {
                     $url = preg_replace('`' . trim($rewrite_rule[0]) . '`i', trim($rewrite_rule[1]), $url);
                 }
             }
         }
     }
     // check for domain aliases
     $das = $site->getSiteSetting('domain_aliases');
     if ($das) {
         $site_domain = $site->getDomainName();
         if (!strpos($url, '://' . $site_domain)) {
             $das = explode(',', $das);
             foreach ($das as $da) {
                 owa_coreAPI::debug("Checking URL for domain alias: {$da}");
                 $da = trim($da);
                 if (strpos($url, $da)) {
                     $url = str_replace($da, $site_domain, $url);
                     break;
                 }
             }
         }
     }
     return $url;
 }
Exemplo n.º 2
0
 /**
  * Filter function Strips a URL of certain defined session or tracking params
  *
  * @return string
  */
 static function makeUrlCanonical($url, $site_id = '')
 {
     if (!$site_id) {
         owa_coreAPI::debug('no site_id passed to make makeUrlCanonical. Returning URL as is.');
         return $url;
     }
     // remove port, pass, user, and fragment
     $url = owa_lib::unparseUrl(parse_url($url), array('port', 'user', 'pass', 'fragment'));
     owa_coreAPI::debug('makeUrlCanonical using site_id: ' . $site_id);
     $site = owa_coreAPI::entityFactory('base.site');
     $site->load($site->generateId($site_id));
     $filter_string = $site->getSiteSetting('query_string_filters');
     if ($filter_string) {
         $filters = str_replace(' ', '', $filter_string);
         $filters = explode(',', $filter_string);
     } else {
         $filters = array();
     }
     // merge global filters
     $global_filters = owa_coreAPI::getSetting('base', 'query_string_filters');
     if ($global_filters) {
         $global_filters = str_replace(' ', '', $global_filters);
         $global_filters = explode(',', $global_filters);
         $filters = array_merge($global_filters, $filters);
     }
     // OWA specific params to filter
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'source');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'medium');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'campaign');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'ad');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'ad_type');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'overlay');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . 'state');
     array_push($filters, owa_coreAPI::getSetting('base', 'ns') . owa_coreAPI::getSetting('base', 'feed_subscription_param'));
     //print_r($filters);
     foreach ($filters as $filter => $value) {
         $url = preg_replace('#\\?' . $value . '=.*$|&' . $value . '=.*$|' . $value . '=.*&#msiU', '', $url);
     }
     //check for dangling '?'. this might occure if all params are stripped.
     // returns last character of string
     $test = substr($url, -1);
     // if dangling '?' is found clean up the url by removing it.
     if ($test == '?') {
         $url = substr($url, 0, -1);
     }
     //check and remove default page
     $default_page = $site->getSiteSetting('default_page');
     if ($default_page) {
         $default_length = strlen($default_page);
         if ($default_length) {
             //test for string
             $default_test = substr($url, 0 - $default_length, $default_length);
             if ($default_test === $default_page) {
                 $url = substr($url, 0, 0 - $default_length);
             }
         }
     }
     // check and remove trailing slash
     if (substr($url, -1) === '/') {
         $url = substr($url, 0, -1);
     }
     // check for domain aliases
     $das = $site->getSiteSetting('domain_aliases');
     if ($das) {
         $site_domain = $site->getDomainName();
         if (!strpos($url, '://' . $site_domain)) {
             $das = explode(',', $das);
             foreach ($das as $da) {
                 owa_coreAPI::debug("Checking URL for domain alias: {$da}");
                 $da = trim($da);
                 if (strpos($url, $da)) {
                     $url = str_replace($da, $site_domain, $url);
                     break;
                 }
             }
         }
     }
     return $url;
 }