From 36f2d7c159dca3a958e96bb913d64c8768dc7518 Mon Sep 17 00:00:00 2001
From: Gina Haeussge <osd@foosel.net>
Date: Sun, 12 Oct 2008 17:50:22 +0200
Subject: [PATCH] Make recognized URL schemes customizable via conf/scheme.conf
 (FS#797)

darcs-hash:20081012155022-2b4f5-177571b9b176bb822015623b62b4d35b98a93d7b.gz
---
 conf/scheme.conf      | 11 +++++++++++
 inc/confutils.php     | 15 +++++++++++++++
 inc/parser/parser.php |  4 ++--
 3 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 conf/scheme.conf

diff --git a/conf/scheme.conf b/conf/scheme.conf
new file mode 100644
index 000000000..88cb3c44d
--- /dev/null
+++ b/conf/scheme.conf
@@ -0,0 +1,11 @@
+#Add URL schemes you want to be recognized as links here
+
+http
+https
+telnet
+gopher
+wais
+ftp
+ed2k
+irc
+ldap
\ No newline at end of file
diff --git a/inc/confutils.php b/inc/confutils.php
index c18b92a02..d735b8b82 100644
--- a/inc/confutils.php
+++ b/inc/confutils.php
@@ -132,6 +132,21 @@ function getWordblocks() {
 }
 
 
+function getSchemes() {
+  static $schemes = NULL;
+  if ( !$schemes ) {
+    $schemes = file(DOKU_CONF.'scheme.conf');
+    if (@file_exists(DOKU_CONF.'scheme.local.conf')) {
+      $local = file(DOKU_CONF.'scheme.local.conf');
+      $schemes = array_merge($schemes, $local);
+    }
+  }
+  $schemes = array_map('trim', $schemes);
+  $schemes = preg_replace('/^#.*/', '', $schemes);
+  $schemes = array_filter($schemes);
+  return $schemes;
+}
+
 /**
  * Builds a hash from a configfile
  *
diff --git a/inc/parser/parser.php b/inc/parser/parser.php
index 804257d03..4cf57b3bf 100644
--- a/inc/parser/parser.php
+++ b/inc/parser/parser.php
@@ -845,7 +845,7 @@ class Doku_Parser_Mode_rss extends Doku_Parser_Mode {
 
 //-------------------------------------------------------------------
 class Doku_Parser_Mode_externallink extends Doku_Parser_Mode {
-    var $schemes = array('http','https','telnet','gopher','wais','ftp','ed2k','irc','ldap');
+    var $schemes = array();
     var $patterns = array();
 
     function preConnect() {
@@ -857,13 +857,13 @@ class Doku_Parser_Mode_externallink extends Doku_Parser_Mode {
         $host = $ltrs.$punc;
         $any  = $ltrs.$gunk.$punc;
 
+        $this->schemes = getSchemes();
         foreach ( $this->schemes as $scheme ) {
             $this->patterns[] = '\b(?i)'.$scheme.'(?-i)://['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
         }
 
         $this->patterns[] = '\b(?i)www?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
         $this->patterns[] = '\b(?i)ftp?(?-i)\.['.$host.']+?\.['.$host.']+?['.$any.']+?(?=['.$punc.']*[^'.$any.'])';
-
     }
 
     function connectTo($mode) {
-- 
GitLab