Патч модуля для редиректа внешних ссылок Gotwo

Многим знаком модуль  gotwo. Он делает редирект внешних ссылок. Неудобство модуля в том что он использует нестандартный тег GO. Решил его поправить. Чтобы не было необходимости использовать нестандартные теги. Так-же в оригинальном модуле создавался новый элемент. Я же решил вносить изменения для редиректа в стандартный тег A если установлен класс GO.
Собственно сами изменения. Прошу указать на ошибки, если что не так.
Меняем только функцию _gotwo_link в файле gotwo.module
Было

<?php
function _gotwo_link($text$filter) {
  
$html_dom filter_dom_load($text);

  $goNodesToRemove = array();
  foreach (
$html_dom->getElementsByTagName('go') as $goNode) {
    
// Clone <go> link to <a> link and keep all attributes intact.
    
$linkNode $goNode->ownerDocument->createElement('a');
    if (
$goNode->attributes->length) {
      foreach (
$goNode->attributes as $attribute) {
        
$linkNode->setAttribute($attribute->nodeName$attribute->nodeValue);
      }
    }

    // Clone all <go> child nodes inside the new <a> tag.
    
while ($goNode->hasChildNodes()) {
      
$childNodes $goNode->childNodes;
      
$linkNode->appendChild($childNodes->item(0));
    }

    // Verify if the url exists in the {gotwo} table. If the url is missing,
    // add the url with link title to the {gotwo} table.
    
$href $goNode->getAttribute('href');
    
$title $goNode->getAttribute('title');

    if (!empty($href)) {
      
$linkNode->setAttribute('href'_gotwo_get_url($href, empty($title) ? NULL $title));
    }

    // Insert the new $linkNode before the previous $goNode.
    
$goNode->parentNode->insertBefore($linkNode$goNode);

    // Save $goNode to remove array. We cannot remove the child here or the DOM
    // index will be cluttered and every second <go> link is not replacement.
    
$goNodesToRemove[] = $goNode;
  }
?>

Стало

<?php
function _gotwo_link($text$filter) {
  
$html_dom filter_dom_load($text);

  $goNodesToRemove = array();
  foreach (
$html_dom->getElementsByTagName('a') as $goNode) {
    
// Clone <go> link to <a> link and keep all attributes intact.
    
if($goNode->getAttribute('class') == 'go') {
    
$href $goNode->getAttribute('href');
    
$title $goNode->getAttribute('title');
    if (!empty(
$href)) {
      
$goNode->setAttribute('href'_gotwo_get_url($href, empty($title) ? NULL $title));
    }
    
  }
  }

  // Now we are able to remove the child's without loosing the index.

  $text filter_dom_serialize($html_dom);

  return trim($text);
}
?>

Источник: http://www.drupal.ru/node/60488

Добавить комментарий к записи "Патч модуля для редиректа внешних ссылок Gotwo"

Чтобы комментировать, необходимо войти в систему.

© 2009 Обзор CMS