diff --git a/boot.php b/boot.php
index 1c558ef70..ac809cce6 100755
--- a/boot.php
+++ b/boot.php
@@ -44,6 +44,7 @@ require_once('include/taxonomy.php');
require_once('include/channel.php');
require_once('include/connections.php');
require_once('include/account.php');
+require_once('include/zid.php');
define ( 'PLATFORM_NAME', 'hubzilla' );
diff --git a/include/channel.php b/include/channel.php
index e35f453de..de685ab4c 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -1371,60 +1371,6 @@ function zat_init() {
-/**
- * @brief Adds a zid parameter to a url.
- *
- * @param string $s
- * The url to accept the zid
- * @param boolean $address
- * $address to use instead of session environment
- * @return string
- *
- * @hooks 'zid'
- * string url - url to accept zid
- * string zid - urlencoded zid
- * string result - the return string we calculated, change it if you want to return something else
- */
-function zid($s,$address = '') {
- if (! strlen($s) || strpos($s,'zid='))
- return $s;
-
- $m = parse_url($s);
- $fragment = ((array_key_exists('fragment',$m) && $m['fragment']) ? $m['fragment'] : false);
- if($fragment !== false)
- $s = str_replace('#' . $fragment,'',$s);
-
- $has_params = ((strpos($s,'?')) ? true : false);
- $num_slashes = substr_count($s, '/');
- if (! $has_params)
- $has_params = ((strpos($s, '&')) ? true : false);
-
- $achar = strpos($s,'?') ? '&' : '?';
-
- $mine = get_my_url();
- $myaddr = (($address) ? $address : get_my_address());
-
- /**
- * @FIXME checking against our own channel url is no longer reliable. We may have a lot
- * of urls attached to out channel. Should probably match against our site, since we
- * will not need to remote authenticate on our own site anyway.
- */
-
- if ($mine && $myaddr && (! link_compare($mine,$s)))
- $zurl = $s . (($num_slashes >= 3) ? '' : '/') . $achar . 'zid=' . urlencode($myaddr);
- else
- $zurl = $s;
-
- // put fragment at the end
-
- if($fragment)
- $zurl .= '#' . $fragment;
-
- $arr = array('url' => $s, 'zid' => urlencode($myaddr), 'result' => $zurl);
- call_hooks('zid', $arr);
-
- return $arr['result'];
-}
// Used from within PCSS themes to set theme parameters. If there's a
// puid request variable, that is the "page owner" and normally their theme
diff --git a/include/hubloc.php b/include/hubloc.php
index b660c1019..17f921f67 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -1,29 +1,5 @@
and will not work if zrl and href appear in a different order.
- *
- * @param array $match
- * @return string
- */
-function zidify_callback($match) {
- $is_zid = ((feature_enabled(local_channel(),'sendzid')) || (strpos($match[1],'zrl')) ? true : false);
- $replace = '= 3) ? '' : '/') . $achar . 'zid=' . urlencode($myaddr);
+ else
+ $zurl = $s;
+
+ // put fragment at the end
+
+ if($fragment)
+ $zurl .= '#' . $fragment;
+
+ $arr = array('url' => $s, 'zid' => urlencode($myaddr), 'result' => $zurl);
+ call_hooks('zid', $arr);
+
+ return $arr['result'];
+}
+
+
+function strip_zids($s) {
+ return preg_replace('/[\?&]zid=(.*?)(&|$)/ism','$2',$s);
+}
+
+function strip_zats($s) {
+ return preg_replace('/[\?&]zat=(.*?)(&|$)/ism','$2',$s);
+}
+
+
+/**
+ * zidify_callback() and zidify_links() work together to turn any HTML a tags with class="zrl" into zid links
+ * These will typically be generated by a bbcode '[zrl]' tag. This is done inside prepare_text() rather than bbcode()
+ * because the latter is used for general purpose conversions and the former is used only when preparing text for
+ * immediate display.
+ *
+ * Issues: Currently the order of HTML parameters in the text is somewhat rigid and inflexible.
+ * We assume it looks like \ and will not work if zrl and href appear in a different order.
+ *
+ * @param array $match
+ * @return string
+ */
+function zidify_callback($match) {
+ $is_zid = ((feature_enabled(local_channel(),'sendzid')) || (strpos($match[1],'zrl')) ? true : false);
+ $replace = '