t3lib_browseLinksHook和自定义链接格式

时间:2012-11-28 11:59:57

标签: typo3

我正在尝试为RTE浏览链接窗口创建一个新选项卡,目的是允许链接到网络共享上的文件。使用外部链接无效,因为TYPO3会自动将http://<domain>/typo3添加到链接中。

我在自定义标签中遇到同样的问题。例如,输入\\<share>\<file>后,该链接最终为http://<domain>/typo3/\\<share>\<file>

钩子类:

class Tx_Test_Hooks_NetworkFolderTree implements t3lib_browseLinksHook
{
  public function init($browseLinks, $additionalParameters)
  {
    $this->browseLinks = &$browseLinks;
  }

  public function getTab($linkSelectorAction)
  {
    global $BE_USER, $LANG;

    $content = '
      <form action="" name="lurlform" id="lurlform">
        <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkURL">
          <tr>
        <td>URL:</td>
        <td><input type="text" name="lurl"'.$this->browseLinks->doc->formWidth(20).' value="" /> '.
        '<input type="submit" value="set" onclick="browse_links_setHref(document.lurlform.lurl.value); browse_links_setAdditionalValue(\'data-htmlarea-external\', \'1\'); return link_current();" /></td>
          </tr>
        </table>
      </form>';

    $content .= $this->browseLinks->addAttributesForm();

    return $content;
  }

  public function parseCurrentUrl($href, $siteUrl, $info)
  {
    if( preg_match('/^([a-z]\:[\/\\\]|\\\{2})/', $href, $matchData) ) $info['act'] = 'unc';

    return $info;
  }

  public function modifyMenuDefinition($menuDefinition)
  {
    global $LANG;

    return array_merge($menuDefinition, array(
                'unc'   => array(
                'isActive'  => ($this->browseLinks->act == 'unc'),
                'label'     =>  'Network file',
                'url'       =>  '#',
                'addParams' =>  'onclick="jumpToUrl(\''.htmlspecialchars('?act=unc&mode='.$this->browseLinks->mode.'&bparams='.$this->browseLinks->bparams).'\');return false;"'
            )
        )
    );
  }

  public function addAllowedItems($currentlyAllowedItems)
  {
    return array_merge($currentlyAllowedItems, array('unc'));
  }

}

1 个答案:

答案 0 :(得分:0)

发现问题。通过PHP parse_url进行检查,返回有关网址的信息数组。如果缺少架构(这是此处的情况),则追加http://