Пример #1
0
 public function filterHtml($html)
 {
     // Fix everything regarding URLs
     $html = MageBridgeHelper::filterContent($html);
     // Replace URLs where neccessary
     $replacement_urls = MageBridgeUrlHelper::getReplacementUrls();
     if (!empty($replacement_urls)) {
         foreach ($replacement_urls as $replacement_url) {
             $source = $replacement_url->source;
             $destination = $replacement_url->destination;
             // Prepare the source URL
             if ($replacement_url->source_type == 0) {
                 $source = MageBridgeUrlHelper::route($source);
             } else {
                 $source = str_replace('/', '\\/', $source);
             }
             // Prepare the destination URL
             if (preg_match('/^index\\.php\\?option=/', $destination)) {
                 $destination = JRoute::_($destination);
             }
             // Replace the actual URLs
             if ($replacement_url->source_type == 0) {
                 $html = str_replace($source . '\'', $destination . '\'', $html);
                 $html = str_replace($source . '"', $destination . '"', $html);
             } else {
                 $html = preg_replace('/href=\\"([^\\"]+)' . $source . '([^\\"]+)/', 'href="' . $destination, $html);
             }
         }
     }
     return $html;
 }
Пример #2
0
 /**
  * Method to redirect to URL replacements
  *
  * @access private
  *
  * @param null
  *
  * @return null
  */
 private function redirectUrlReplacement()
 {
     // Initialize variables
     $enabled = $this->getParam('enable_urlreplacement_redirect', 1);
     $post = $this->input->post->getArray();
     // Exit if disabled or if we are not within the MageBridge component
     if ($enabled == 0 || !empty($post) || $this->input->getCmd('option') != 'com_magebridge') {
         return;
     }
     // Fetch the replacements and check whether the current URL is part of it
     $replacement_urls = MageBridgeUrlHelper::getReplacementUrls();
     if (!empty($replacement_urls)) {
         foreach ($replacement_urls as $replacement_url) {
             $source = $replacement_url->source;
             $destination = $replacement_url->destination;
             // Prepare the source URL
             if ($replacement_url->source_type == 0) {
                 $source = MageBridgeUrlHelper::route($source);
                 $source = preg_replace('/\\/$/', '', $source);
             }
             $source = str_replace('/', '\\/', $source);
             $source = preg_replace('/^(http|https)/', '', $source);
             // Prepare the destination URL
             if (preg_match('/^index\\.php\\?option=/', $destination)) {
                 $destination = JRoute::_($destination);
             }
             // Fix the destination URL to be a FQDN
             if (!preg_match('/^(http|https)\\:\\/\\//', $destination)) {
                 $destination = JURI::base() . $destination;
             }
             if ($replacement_url->source_type == 1 && preg_match('/' . $source . '/', JURI::current())) {
                 header('Location: ' . $destination);
                 exit;
             } else {
                 if ($replacement_url->source_type == 0 && preg_match('/' . $source . '$/', JURI::current())) {
                     header('Location: ' . $destination);
                     exit;
                 }
             }
         }
     }
 }