Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by zer0 ( 14 years ago )
<?php
defined('JPATH_BASE') or die;

jimport('joomla.plugin.plugin');

class plgSystemMvExternalLinks extends JPlugin
{
 var $skip = null;

 function __construct(&$subject, $config) {
  parent::__construct($subject, $config);
  $params = &JComponentHelper;::getParams( 'com_mvexternallinks' );
  $this->skip = explode("\n", $params->get('skip', ''));
 }

 function onAfterRender( ) {
  
  // В админке плагин не работает
  $uri = JFactory::getURI();
  if( strpos( $uri->getPath(), '/administrator/' ) === 0 ){
      return true;
  }
  
  // Взять весь html-код страницы и обработать в нем все ссылки
  $html = JResponse::getBody();
  $html = preg_replace_callback('/(<a\s+.*?href\s*=(["|\']?))(.*?)(\2.*?>)/i', array($this, 'urlPeplace'), $html);
  JResponse::setBody($html);
 }
 
 function urlPeplace(&$matches) {
  $url = $matches[3];
  // Если ссылка внутренняя - ничего делать не надо
  if(JURI::isInternal($url)) return $matches[0];
  
  $uri = new JURI($url);
  // Проверить не надоли пропустить адрес
  $host = $uri->getHost();
  if(strpos($host, 'www.') === 0) $host = substr ($host, 4);
  if(array_search($host, $this->skip) !== false) return $matches[0];
  
  // Возвращаем ссылку с подмеденным url
  $url = JRoute::_('index.php?option=com_mvexternallinks&url;='.base64_encode($url));
  return $matches[1].$url.$matches[2].$matches[4];
 }
 
}

 

Revise this Paste

Your Name: Code Language: